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

christopheradams
I was recently asked to step up and become the maintainer for the Elixir Style Guide. It was, I believe, the first, and is now the most p...
New
New
ivanminutillo
Bonfire is an open source framework for building modular federated digital spaces. It’s built entirely with Elixir, including LiveView (a...
New
szsoppa
Hey folks! For the third year in a row, we’re running the Elixir Survey by Curiosum! It’s been live since yesterday, and 300+ people hav...
New
AstonJ
@Garrison’s comment in another thread reminded me of this post by Joe: With the big five exerting more control than ever, new (AI) play...
New
derpycoder
So, anyone got a chance to look at this?!? I’m kind of glad this came along. We can just throw this into our Auth pages and won’t have t...
New
sym_num
I created a Forth processor in Elixir. This is my hobby project. https://github.com/sasagawa888/Forth
New
rhcarvalho
Very interesting value proposition! Having watched some interviews with Elm’s creator recently, I wanted to ask where you stand in terms...
New
travisf
In upgrading from Ecto 2 to Ecto 3 I’m dealing with a failing test. If I use ExMachina build(:address) I’ll get an error trying to put_e...
New
AstonJ
A remark @Garrison made… ..has already inspired a thread for the technical side of reclaiming our internet, but there is of course anot...
New

Other popular topics Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement