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

mbenatti
Following https://github.com/tbrand/which_is_the_fastest |&gt; https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
nunobernardes99
Hi there Elixir friends :vulcan_salute: In a recent task I was on, I needed to check in two dates which of them is the maximum and which...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
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