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:

https://github.com/ryanrasti/typegres

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.

Last Post!

ryanrasti

ryanrasti

Thanks! I didn’t know about LINQ inspiring Ecto, it definitely is an inspiration for Typegres.

The design goals of Typegres and LINQ are similar in the sense of providing a query builder that feels idiomatic in the host language (Typescript/C# respectively). In fact the fluent API looks pretty similar in both (similar to pipe-based query building – e.g., |> where in Ecto)

The similarities mostly end there though. LINQ was designed to be generic over arbitrary datasources (e.g., in memory, xml files, etc.) Typegres is designed to feel like you’re importing 100% of Postgres, with additional idiomatic TypeScript on top.

Since you know Ecto well - are there specific features or patterns from it that you think are essential to get right or additional avenues you’d think are worth exploring?

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
pillaiindu
In django there is a cache framework backed by memcached. Rails also puts a lot of emphasis on caching, and even the idea of russian-doll...
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
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

We're in Beta

About us Mission Statement