5 ms·
The big problem is that raw SQL has pretty bad type inference and linting support in most editors. A query builder can still give you a lot of type safety benef
by valzam 3mo ago
The big problem is that raw SQL has pretty bad type inference and linting support in most editors. A query builder can still give you a lot of type safety benefits.
- ai_slop_hater 3mo ago[flagged]
- allthetime 3mo agoFor the vast majority of simple use cases the common subset of all popular SQLs is exactly the same. Otherwise… just use Postgres
- deleted 3mo ago[deleted]
- photios 3mo agoIt's not that different. I'd rather have a different way to do UPSERTs or a different window function here and there [1] than figure out every ORM's join syntax or its sneaky ways to SELECT N+1 me into oblivion. [1] LLMs make these very easy to handle.
- dagss 3mo agoI would argue that is a bit like complaining there is no "backend language" and that Java, Rust, Go all have different syntax. The choice of DB is arguably more important than the choice of backend language.
- threethirtytwo 3mo ago[dead]
- rmunn 3mo agoAutocomplete is making me lazy. If I don't see what I'm about to type within two or three characters, I feel like the IDE isn't doing its job of helping me. So being able to type `db.Cust` and autocomplete Customers is really nice. I do know SQL, but yes, the language servers usually have a harder time connecting the SQL to my backend code, whatever language it's in, without quite a lot of config fiddling that pretty much obviates any time savings I would have gained from autocomplete.
- NetOpWibby 3mo agoIn my database[0] you get an SDK generated from your schema. Typescript is the default and man, the autocomplete works so well. I recently added support for SDK generation in Rust and Go, just do `disc codegen —rust` (double dash, my iPad is autocompleting the wrong dash) and you’re good to go. [0]: https://disc.sh https://disc.sh
- smw 3mo agoI'm firmly on the ORM side of things, despite knowing SQL very well -- but your IDE/editor can fix this with bare sql. Try using Jetbrains Datagrip or the DB integration in Idea or one of the other language-specific IDEs.
- dadie 3mo agoI think the bigger problem is that SQL is in almost every language a second-class citizen. And even calling it second-class can be seen as a stretch.
- ambicapter 3mo agoI’m a SQL-lover and ORM-hater but I don’t see why any language would support another wholly different language as a first-class citizen.
- xigoi 3mo agoIdeally, SQL wouldn’t be a wholly different language, but a library with bindings for various languages.
- meindnoch 3mo agoThat's why it's called SQL aka String Query Language. The queries are just strings.
- mijowi 3mo agoAre you being cheeky? The S stands for Structured.
- ako 3mo agoTime to start using plsql, ADA with first class support for embedded SQL.
- pjmlp 3mo agoWhich is why one is better off using IDEs, especially those from DB vendors.
- Arch-TK 3mo agoA query builder is not an ORM. ORMs build queries for you, but a query builder does not need to be an ORM.
- win311fwg 3mo agoORMs do not inherently build queries. They only provide data transformations between relations (i.e. rows and columns) and objects. Hence the literal name: Object relation mapping. You can absolutely have ORM without query building just as much as you can have query building without ORM. Sometimes ORMs and query builders are combined into a higher order system, such as what is described by the active record pattern. This might be what you are actually thinking of instead?
- Arch-TK 3mo agoOkay, so I have an object like: User { name friends: List<Friend> posts: List<Post> } Let's say we have a "MappedUser" which is derived from this type by this ORM. I now do: user = get_mapped_user() for post in user.friends[0].friends[0].posts { ... } Ignoring "get_mapped_user()" how does our user object work? What happens when I access `.friends`? Does it give me an empty list, because I didn't ask for it? I am not aware of anything that calls itself an ORM which merely does: user: User = map_from_relational_to_user(query_user()) Not only is it difficult to conceptualise how this operation would ever meaningfully work for any non-trivial query, it's also difficult to see how it would even work for trivial queries. ORMs, at their core, try to abstract away something like `user.friends[0].friends[0].posts` more or less into some underlying queries against a relational database. The main distinction between them being in the availability and first-class nature of the escape hatches when this operation inevitably becomes slow.
- win311fwg 3mo ago> Does it give me an empty list, because I didn't ask for it? That depends on the rest of your code. If you are using something like the active record or data mapper pattern then it would reach out and fetch more results. If you don't have such mechanics in place then an empty list is possible. We don't have enough information here to say what happens. > I am not aware of anything that calls itself an ORM which merely does When your code merely does that, what do you call it? > ORMs, at their core, try to abstract away something like `user.friends[0].friends[0].posts` more or less into some underlying queries against a relational database. Active record/data mapper tries to abstract that. ORMs are a necessary piece of active record/data mapper, but one part of a larger system. You also need things like a query builder. ORM alone is not sufficient for these patterns. > into some underlying queries against a relational database. Unlikely. SQL is mentioned in the headline for a reason. Nobody uses relational databases in the real world. The only remaining relational database engines that are still maintained really only exist for educational purposes. I understand why you might think a relational database is necessary given that ORM stands for Object Relational Mapping, but as ORM operates on data, not databases, the data can be relational even if the backing database isn't. It simply becomes another mapping step to see them become compatible.
- therealdrag0 3mo agoUse testcontainers and make sure you have an integration test for every query..