Hello everyone, I'd like to ask if you have ever wanted to execute the following query in bun
Have you ever wanted to execute the following query in bun?
INSERT INTO table_name (value1) VALUES ($1);
The $1 and $2 parts of the above query are PostgreSQL placeholders.
You can execute the query by calling the Exec method with the standard package sql.DB.
DB.Exec() and sql.DB.Exec() are methods of different structures, so it does not matter that they behave differently.
Each RDBMS (MySQL, PostgreSQL, Oracle...) Exec() is probably used to abstract the notation of each RDBMS (MySQL, PostgreSQL, Oracle...).
However, it would be nice to have compatibility with each DB engine's own notation.
From my research, it works with PostgreSQL placeholders by simply modifying the following sentence in db.go.
I don't know how many people will be happy with this change, but at least I'm happy to make the best ORM while keeping compatibility, as I was initially confused by the PostgreSQL placeholders not working.
By the way, the following works because sql.DB embedded in bun.DB is public.
db.DB.Exec()
When used this way, Exec in *sql.DB is executed and works with placeholders like $1 without problems. (db=bun.DB, db.DB: sql.DB)
Hello everyone, I'd like to ask if you have ever wanted to execute the following query in bun
Have you ever wanted to execute the following query in bun?
The
$1
and$2
parts of the above query are PostgreSQL placeholders. You can execute the query by calling the Exec method with the standard packagesql.DB
.However, when I call the Exec method using bun.DB, I get the following error.
On the other hand, using
?
as a placeholder can be used to execute successfully.DB.Exec() and sql.DB.Exec() are methods of different structures, so it does not matter that they behave differently. Each RDBMS (MySQL, PostgreSQL, Oracle...) Exec() is probably used to abstract the notation of each RDBMS (MySQL, PostgreSQL, Oracle...). However, it would be nice to have compatibility with each DB engine's own notation.
From my research, it works with PostgreSQL placeholders by simply modifying the following sentence in
db.go
.I don't know how many people will be happy with this change, but at least I'm happy to make the best ORM while keeping compatibility, as I was initially confused by the PostgreSQL placeholders not working.
By the way, the following works because sql.DB embedded in bun.DB is public.
db.DB.Exec()
When used this way, Exec in *sql.DB is executed and works with placeholders like $1 without problems. (db=bun.DB, db.DB: sql.DB)