News for hackers. Stuff that matters.
Re:PostgresJs: The Fastest full featured PostgreSQL client f... by cultofmetatron on Saturday October 14, 2023 @03:33PM (#37883539)
the list would merit its own dedicated blog post but to highlight a few nice parts, ecto lets me write sql code in elixir. it does not try to wrap it all into objects but I do get schemas. so for instance I can create a schema `Player` which maps to a table "players"

I can then get them via ``` from(p in Player) |> where([p], p.id in ^player_ids) |> select([p], p) |> Repo.all()

```

need to join with an association?

```

from(p in Player) |> join([p], s in assoc(p, :scores), as: :score) |> where([p], p.id in ^player_ids) |> preload([p, score: s], [score: s]) |> select([p], p) |> Repo.all() ```

this gets me all players with their scores.

need to get the sum of scores for all players?

```

from(p in Player) |> join([p], s in assoc(p, :scores), as: :score) |> where([p], p.id in ^player_ids) |> select([p], %{ player_id: p.id, score: sum(score.value) }) |> group_by([p, score: s], [p.id]) |> Repo.all() ```

as you can see, you can unwind this pretty fast to sql in your head. but you can also let the system just grab the kitchen sink when you jsut need to get somethign working fast. and its all very easy to modify and decuple.

this is hardly exhaustive though, I could spend a day talking about ecto. I spent 8 years developing in nodejs but now I work exclusively in elixir. unless what you're doing is 90% done by existing libraries, its juts a better tool for building highly performant backends.

Re:PostgresJs: The Fastest full featured PostgreSQL client f... by spion on Saturday October 14, 2023 @04:53PM (#37884181)
Have you tried drizzle? https://orm.drizzle.team/docs/select#aggregations

(note: it produces type-safe results too)

Re:PostgresJs: The Fastest full featured PostgreSQL client f... by KRAKRISMOTT on Saturday October 14, 2023 @06:13PM (#37884723)
Their migrations tool is proprietary and not open-source. The project is basically an open source bait and switch riding off the edge computing hype (since prisma and other major JS ORMs have poor support for edge environments).
Re:PostgresJs: The Fastest full featured PostgreSQL client f... by spion on Monday October 16, 2023 @09:54AM (#37899939)
You don't need to use drizzle migrations. There are much better migration tools.
Re:PostgresJs: The Fastest full featured PostgreSQL client f... by invaliduser on Saturday October 14, 2023 @05:31PM (#37884447)
This is probably great to use, but it also highlights in comparison the beautiful simplicity of SQL. Doing something simple is hard, and SQL is so simple that I think most people find little value to abstractions built on it.
Re:PostgresJs: The Fastest full featured PostgreSQL client f... by kiliancs on Sunday October 15, 2023 @10:18AM (#37889940)
There are different valid ways to produce these queries, some of which might be less composable but simpler: https://hexdocs.pm/ecto/Ecto.Query.html