this post was submitted on 29 Mar 2024
14 points (88.9% liked)

SQL

469 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?

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 1 points 8 months ago (1 children)

The classic example is the N+1 query pattern, where the number of generated queries is linear in the number of rows returned by the first query.

[โ€“] [email protected] 6 points 8 months ago

This is not a problem for a modern ORM, JOINs are supported by most ORMs I've worked with for many years.

Var cars = await db.Cars
    .Include(c => c.Wheels)
    ToListAsync();

foreach (var car in cars)
{
    Console.WriteLine(car.Model);
    foreach (var wheel in car.Wheels)
    {
        Console.WriteLine(wheel.Id);
    }
}

This will get all the cars and their associated wheels in 1 single query by performing a JOIN operation using Entity Framework Core, assuming there's a FK for Wheel to Car.