Query Attached Databases in SQLite

Hey so I am using drizzle with my local sqlite db, I have several databases which I at runtime attach to the main sqlite database. I need to query across each of these is there a reasonably nice way to do this through the orm? Maybe some sort of aliasing? currently I am forced to do some sort of sql generation in the orm
const insertSql = db
.insert(groupMessages)
.values(optimisticMessage as GroupMessage)
.returning()
.toSQL()
const insertSql = db
.insert(groupMessages)
.values(optimisticMessage as GroupMessage)
.returning()
.toSQL()
which I then loop over a replace with the correct database aliases
const newMessage = db.get(sql.raw(replaceParams( insertSql.sql.replace('"groupMessages"',`"${databaseAlias}"."groupMessages"`),
insertSql.params,
),
),
)
const newMessage = db.get(sql.raw(replaceParams( insertSql.sql.replace('"groupMessages"',`"${databaseAlias}"."groupMessages"`),
insertSql.params,
),
),
)
But this is pretty ugly and not sql injection safe. Any ideas on how to go about this? I guess a similiar issue would be multiple table schemas in other databases like postgres. Is there a standard approach on how to handle these situations at the minute?
1 Reply
Amos
Amos11mo ago
Did you ever get any answers about this or figure it out? Also interested in something like this

Did you find this page helpful?