ryanrasti

ryanrasti

Curious to hear what Elixir users think of my library Typegres - the magic of Ecto, reimagined for Typescript and Postgres

Hey everyone – after coming off of 3 years building with Ecto, I’ve been working non-stop on Typegres, a new query builder that strongly aligns with Ecto’s philosophy around composabilty & purity.

The core, novel idea: write class methods that compile directly to composable SQL (try it in the playground)

// Extend your models
class Post extends posts.asClass<Post>() {
  // by writing methods
  trendingScore() {
    return this.likes.divide(this.ageInHours().plus(2)); // → SQL, not JS!
  }
}
// and use them anywhere in your queries:
await Post.select((p) => ({
  content: p.content,
  trending: p.trendingScore(),
}))
  .orderBy((p) => p.trendingScore()) // Everything composes into a single query, just like Ecto

What you’ll appreciate coming from Ecto:

  1. Composability: Everything is composable SQL expressions (and since it’s Typescript, it’s fully typed too)
  2. Purity: no N+1 queries or obscure magic – just a translation layer meant to maximize the synergy between TypeScript and Postgres

What makes Typegres different:

  1. True OOP in SQL: Encapsulate business logic in methods (post.trendingScore()) instead of scattered helper functions (and relations and graph-based querying naturally follow as a result of the composability). This a huge step towards resolving the object-relational impedance mismatch
  2. Postgres, Postgres, Postgres: coverage for all 3000+ built-in functions/operators without SQL strings (with coverage for all statements in the works)

Github:

As a huge admirer of Ecto, I’d love to hear what this community thinks. Does this approach to unifying objects and SQL resonate with you?

Most Liked

billylanchantin

billylanchantin

Very cool! I think Ecto gets a lot right, so I’m glad to see others working on the problem from that direction rather than ORMs.

Probably there won’t be a ton of traction on this forum about the OOP aspects of Typegres since Elixir isn’t object-oriented. But since you brought up Ecto, how does Typgres compare to Linq?

From what I understand, the Ecto developers drew inspiration from Linq. And I believe Linq was originally for C#, an OOP language, so there may be more overlap in terms of design goals.

Where Next?

Popular in Discussions Top

jdumont
I could write forever about this, but I’ll do my best to keep it succinct. For anyone familiar with event sourcing, what is your opinion...
New
bartblast
With the core component system and HTTP/WebSocket infrastructure solid, it’s time to tackle Pub/Sub support. What We Have vs What’s Miss...
New
AstonJ
Have you changed the way you learn? Maybe you started off using docs and tutorials and are now an avid book reader or course watcher? Or ...
New
yolo007wizard
I’ve been reading up on Firefly and it looks very impressive. Does this mean faster CPU bound Elixir? i.e. ballpark java speeds? Or at le...
New
bartblast
Some great comments in the home page thread shifted toward what you’d like to see in Hologram’s future, particularly standalone mode. I’v...
New
matreyes
I haven’t seen this paper being discussed by the community, but I think this makes Elixir more relevant than ever. TLDR; The paper...
New
dogweather
I’ve been brainstorming about ways to solve the N-dimensional code organization problem, and am thinking about developing a Smalltalk-lik...
New
chrisliaw
Hi, I’m wondering is it my thinking process or this is the norm among the Elixir developer for the use of Struct and accessor functions ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
AstonJ
There seems to be a lot of buzz around DeepSeek at the moment, with some saying it’s a ChatGPT killer. The most remarkable thing (if they...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement