How to join tables from different dbs in same db cluster?
Hi is there the possibility to join tables from different schemas?
We have a mariadb cluster with different schemas and would like to join tables from different schemas. Is that already possible with drizzle?
1 Reply
Something like this:
import { tableA } from "db/db1/schema";
import { tableB } from "db/db2/schema";
const result = db1.select().from(tableA).leftJoin(tableB, eq(tableA.id, tableB.tableAId))
leads to an error like Table 'db1.tableB' doesn't exist.
Although intellisense gets the types right.
relations were defined like this:
const tableBRelations = relations(tableB, ({many}) => ({
tableAThings: many(tableA)
}))
and
const tableARelations = relations(tableA,
({one}) => ({
tableBThing: one(tableB, {
fields: [tableA.tableBReferenceId],
references: [tableB.id]
})
}))
Is there a way to explicitly declare which db/table-combination we want to join?