singgih
singgih
DTDrizzle Team
Created by singgih on 8/7/2024 in #help
Modify Table type object
i found it
export function crossDBTable<T extends MySqlTable>(
dbName: Database,
data: T,
): T {
const tableName = `${dbName}\`.\`${getTableName(data)}`;
const table = new MySqlTable<{
name: string;
schema: undefined;
columns: T["_"]["columns"];
dialect: "mysql";
}>(tableName, undefined, tableName);

const tableColumns = getTableColumns(data);
const columns = extractKeys(tableColumns).reduce(
(acc, key) => {
const column = tableColumns[key];

return {
...acc,
[key]: Object.assign(column, {
table: table,
}),
};
},
{} as Record<string, MySqlColumn>,
);

const newTable = Object.assign(table, columns);

return newTable as unknown as T;
}
export function crossDBTable<T extends MySqlTable>(
dbName: Database,
data: T,
): T {
const tableName = `${dbName}\`.\`${getTableName(data)}`;
const table = new MySqlTable<{
name: string;
schema: undefined;
columns: T["_"]["columns"];
dialect: "mysql";
}>(tableName, undefined, tableName);

const tableColumns = getTableColumns(data);
const columns = extractKeys(tableColumns).reduce(
(acc, key) => {
const column = tableColumns[key];

return {
...acc,
[key]: Object.assign(column, {
table: table,
}),
};
},
{} as Record<string, MySqlColumn>,
);

const newTable = Object.assign(table, columns);

return newTable as unknown as T;
}
3 replies
DTDrizzle Team
Created by singgih on 8/7/2024 in #help
Modify Table type object
i just thinking maybe if i modify the table name = db_name.table_name then drizzle can automatically parsing the value as table name from cross database. also recognize it as Table then will automatically add Select query in my innerjoin sql query.
3 replies
DTDrizzle Team
Created by sayuto on 8/6/2024 in #help
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB typ
try to add typeof you schema.
import * as yourSchema from './path-your-schema'
const db = drizze<typeof yourSchema>()
import * as yourSchema from './path-your-schema'
const db = drizze<typeof yourSchema>()
9 replies