Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support SqlDelight modules to implement PostgreSql extensions #5677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Mar 5, 2025

☢️ Experimental
🐙 Use the SqlDelight module service loader (see sqlite json-module )to implement Postgresql 3rd party extensions - rather than add in the PostgreSql grammar or having to create a new sub dialect.

sqldelight {
   databases {
       create("Sample") {
           dialect(libs.sqldelight.postgresql.dialect)
           module(project(":postgis-module")) // module can be local project or external dependency
       }
   }
}

🧪 Example extension modules using these changes:

bm25 - text search - https://github.com/griffio/sqldelight-bm25-module-app
pgvector - vector embeddings - https://github.com/griffio/sqldelight-pgvector-module-app
postgis - ever popular - https://github.com/griffio/sqldelight-postgis-module-app

  • Open PostgreSqlTypeResolver for inheritance to allow calling into subclasses - delegation is not enough
  • Public PostgreSqlType for modules to access existing PostgreSql types
  • Add protected booleanBinaryExprTypes as modules can add boolean binary operator types

@sausti
Copy link

sausti commented Mar 23, 2025

👋 @griffio This is great! Are there any plans to move this out of a draft state and merge it for use in snapshot builds? We're using SQLDelight now with Postgres and were hoping to leverage pgvector.

@griffio griffio force-pushed the postgresql-modules branch from 30b4fe7 to fb1d1fd Compare March 23, 2025 17:56
@griffio griffio marked this pull request as ready for review March 23, 2025 18:23
@griffio
Copy link
Contributor Author

griffio commented Mar 23, 2025

OK have set for review - I implemented several interesting extensions to see what problems and work-arounds are needed.

Keep in mind SqlDelight is really for basic Sql operations -
There are still many Postgresql built-in features not implemented in SqlDelight that some of these extensions may use - e.g. Schemas, Create Functions, Triggers.

@sausti
Copy link

sausti commented Mar 24, 2025

OK have set for review - I implemented several interesting extensions to see what problems and work-arounds are needed.

Keep in mind SqlDelight is really for basic Sql operations - There are still many Postgresql built-in features not implemented in SqlDelight that some of these extensions may use - e.g. Schemas, Create Functions, Triggers.

Thank you! And, of course. Our PostgreSQL use cases are straightforward (no need for Triggers, etc.). Your change here unblocks pgvector and AI Vector embedding models, which is really what we're (and I'm sure others!) are excited about.

@griffio griffio force-pushed the postgresql-modules branch from fb1d1fd to 09e56d6 Compare March 25, 2025 08:56
griffio added 2 commits March 27, 2025 13:21
Make the PostgreSqlType public so it can be accessed in third party modules
open PostgreSqlTypeResolver for extension and polymorphic calls
booleanBinaryExprTypes is a new protected method to allow subclasses to add types
@griffio griffio force-pushed the postgresql-modules branch from 09e56d6 to 7a817c1 Compare March 27, 2025 13:51
@griffio
Copy link
Contributor Author

griffio commented Mar 31, 2025

@hfhbd Can this be approved and merged for snapshot testing? I implemented 3 example modules to test it
Follows on from #5625
This is an alternative approach to including third party extensions e.g #5602 and avoids having to create a new dialect

@DRSchlaubi
Copy link

Any update on snapshots?

@AlecKazakova
Copy link
Collaborator

love seeing stuff being built as extensions <3

@AlecKazakova AlecKazakova merged commit 662e250 into sqldelight:master May 13, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants