Making query generation less dependant on model. #278
Replies: 3 comments 4 replies
-
We can definitely make model optional.
I guess we would need to support something like this col1 := bun.NewColumn("col1").Type(sqltype.Blob).AutoIncrement()
db.NewCreateTable().AddColumn(col1) So drivers have a chance to translate
I guess it could work for some common cases if you are willing to make some compromises in order to support different DBMS. Which brings the question - do you really need to support different DBMS and are ready to invest some time into it? :) Because many simple things become complicated when you want to do it for all 3 DBMS... |
Beta Was this translation helpful? Give feedback.
-
@vmihailenco Do you think the This way we could create a |
Beta Was this translation helpful? Give feedback.
-
On a slightly separate note; using sqltypes to have a single value to represent a type across the databases is good. But do you think the provided types are exhaustive enough? Or could something be implemented on the dialect level for some nuanced types? Like |
Beta Was this translation helpful? Give feedback.
-
I'm currently migrating a large project from go-pg to bun. As I would love to be able to add support for multiple databases for self-hosted options. To that end, I need to convert my current SQL-based migrations (which are PostgreSQL focused) to go based migrations that might need to take into account differences in databases. For example:
But this type of approach isn't currently supported by bun, as it required a model struct be provided in order to generate the queries.
I'm wondering if there would be a way to expose more basic versions of methods like
addField
publically so they can be leveraged programmatically rather than a strictly typed struct?To that end it would let me migrate all of my existing migrations to bun nearly line for line (albeit in golang instead of SQL) and achieve an identical final DB state when compared to go-pg. While also supporting other databases like SQLite.
Other databases might need additional nuances as well. For example; a 00000000000000_init.go migration might be different between databases. In Postgres it might need to install extensions; in SQLite it might need to run
PRAGMA foreign_keys = ON;
I might be overcomplicating things a bit and if I am please let me know; I really just want to be able to support all 3 databases with a single code base and as similar a migration structure between the DBs as possible.
Curious what your thoughts are @vmihailenco
Beta Was this translation helpful? Give feedback.
All reactions