this post was submitted on 29 Mar 2024
7 points (100.0% liked)

SQL

2 readers
1 users here now

Related Fediverse communities:

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

Is there a programming language specifically designed for interacting with SQL databases that avoids the need for Object-Relational Mappers (ORMs) to solve impedance mismatch from the start?

If such a language exists, would it be a viable alternative to PHP or Go for a web backend project?

top 18 comments
sorted by: hot top controversial new old
[–] MariusGundersen@programming.dev 30 points 6 months ago (1 children)
[–] charolastra@programming.dev 3 points 6 months ago

Came here to say this

[–] ramble81@lemm.ee 15 points 6 months ago (4 children)

ORMs are one of the worst things ever created IMO. Sure they’re great to turn structured data storage into objects and methods that developers are used to, but every single one of them scales for crap and I can’t tell you the number of projects we have to go back and fix to be straight up raw SQL once it starts growing and becomes a bottleneck.

(I’ll get off my soapbox now)

[–] eluvatar@programming.dev 6 points 6 months ago

It's just a performance to development time trade off. Clearly the product was successful enough to demand coming back to improve the performance. Lots of software fails before it even reaches that point.

[–] NostraDavid@programming.dev 2 points 6 months ago

Argh, your comment is such a pet peeve of mine, especially since my SQL knowledge is kinda arse (it's #1 of my todo list to learn): "just use raw SQL" is a terrible answer, because newbies now still don't know how to not use an ORM (and building classes is what they tend to know, so using a wrapper like Django or SQL Alchemy is ez pz).

How do I learn to use raw SQL, as a way to not use ORMs. Yes, learning SQL is step 1, but what is step 2? How am I going to do migrations, without having to manually run stuff, because manual work is faulty work. How am I going to track changes in my model, over time?

Sorry if I sound frustrated, because I am.

load more comments (2 replies)
[–] thesmokingman@programming.dev 6 points 6 months ago (1 children)

Have you considered raw queries (properly parametrized and escaped and all that)? You can’t beat the speed of getting exactly what you need with no overhead.

What you’re describing is basically a fancy ORM.

[–] veer66@lemmy.one 1 points 6 months ago (1 children)

properly parametrized and escaped and all that

I'm not sure if what I use is proper enough in your sense. So, can you elaborate more?

[–] boatswain@infosec.pub 4 points 6 months ago (1 children)
[–] veer66@lemmy.one 1 points 6 months ago* (last edited 6 months ago)

Yes, I've used this.

[–] echindod@programming.dev 3 points 6 months ago (1 children)

Everyone else has more experience than I, and I am not sure these are exactly the kinds of answers you are looking for...but the two things I have thought is using something like PL/SQL and stored procedures, so much of your backend logic is removed from the server and set into the database itself. Not exactly what you are looking for I think, and it has problems of its own.

Second, Prolog is a great query language (from what I am told) and capable of running a server. TerminusDB runs their server in prolog, and also postgres has a prolog implementation. It would be interesting to play with these things, but they may not exactly be what you are looking for.

[–] veer66@lemmy.one 1 points 6 months ago (1 children)

Stored procedure and Datalog are not what I'm looking for. However, I should consider them seriously, since they may be more practical.

[–] echindod@programming.dev 1 points 6 months ago (1 children)

I am not as familiar with RDBMs internals, but you could also build your server in the database. Right now, I am building a server client of sorts with Oxigraph. I have a store object that I am manipulating directly with rust code. It is an option. However its not going to be very flexible, and it does complicate the sanitization issues.

Also, prolog is a complete language, very capable of running the server. I don't know what kind of architecture you are thinking of and having the distinction between datalog on the database and prolog in the server might be problematic. Also, I may be projecting a little. I wish I could be using prolog. But alas.

[–] veer66@lemmy.one 2 points 5 months ago

I don’t know what kind of architecture you are thinking of and having the distinction between datalog on the database and prolog in the server might be problematic.

I thought about Datomic and Clojure.

[–] agilob@programming.dev 2 points 6 months ago

It really depends on where you set the limit on what ORM is, JOOQ is kind of a thing you're looking for.

[–] NigelFrobisher@aussie.zone 2 points 6 months ago (1 children)

Don’t, you’ll invoke all the DBAs from the 90s who all seem to hang out here.

[–] veer66@lemmy.one 1 points 5 months ago

I did. I also coded in PL/pgSQL.

[–] Nithanim@programming.dev 2 points 6 months ago

As pixxelkick already said, you most likely need some kind of mapping anyway between backend sql and frontend json. If you would have a language designed for interacting with sql databases it would probably suck for everything else.

In java with jooq and its generator it works pretty well, actually. You get the database types as java types and have rather safe queries. Type support breaks down for large and complicated queries, though.