asch
asch
Explore posts from servers
DTDrizzle Team
Created by asch on 8/29/2024 in #help
Does drizzle support querying across multiple mysql databases (same mysql server)?
Here's some 'rough' code to demonstrate what I'm attempting to do... basically I have tables in two mysql databases (same mysql server). I can write SQL to query data from tables in different databases, but am struggling to get drizzle to do it. I saw that drizzle allows defining the database with mysqlSchema(). Looking at the query that is being generated, it is not using the mysql database (mysqlSchema). When the query is generated, it thinks both tables in the same mysql database (mysqlSchema). Maybe the 'rqb' doesn't support multiple databases or does drizzle not support querying across them yet?
const schema1 = mysqlSchema('schema1');
const schema2 = mysqlSchema('schema2');

const table_a = schema1.table('table_a', {
id: int('id'),
});
const table_b = schema2.table('table_b', {
id: int('id'),
tblA_ref: int('a_ref').references(() => table_a.id),
});

const tbl_b_relations = relations(table_b, ({ one }) => ({
tblA: one(...)
});

const schema = { table_a, table_b, tbl_b_relations };

const poolConnection = mysql.createPool(...);

const db = drizzle(poolConnection, {
...,
schema
});

const results = db.query.table_b.findMany({
with: {
tblA: true
},
});
const schema1 = mysqlSchema('schema1');
const schema2 = mysqlSchema('schema2');

const table_a = schema1.table('table_a', {
id: int('id'),
});
const table_b = schema2.table('table_b', {
id: int('id'),
tblA_ref: int('a_ref').references(() => table_a.id),
});

const tbl_b_relations = relations(table_b, ({ one }) => ({
tblA: one(...)
});

const schema = { table_a, table_b, tbl_b_relations };

const poolConnection = mysql.createPool(...);

const db = drizzle(poolConnection, {
...,
schema
});

const results = db.query.table_b.findMany({
with: {
tblA: true
},
});
5 replies
KKysely
Created by asch on 6/19/2023 in #help
How to insert into all values (and columns) from another table / view?
I realize I could write the raw sql, however I was curious how I would go about creating the following insert statement using kysely. insert into <table> select * from <view_or_table> I was looking over https://kysely-org.github.io/kysely/classes/InsertQueryBuilder.html#values but haven't been able to figure it out.
4 replies