drizzle-orm
Version:
Drizzle ORM package for SQL databases
53 lines (49 loc) • 1.65 kB
JavaScript
import { Client } from "@planetscale/database";
import { DefaultLogger } from "../logger.js";
import { MySqlDatabase } from "../mysql-core/db.js";
import { MySqlDialect } from "../mysql-core/dialect.js";
import {
createTableRelationsHelpers,
extractTablesRelationalConfig
} from "../relations.js";
import { PlanetscaleSession } from "./session.js";
function drizzle(client, config = {}) {
if (!(client instanceof Client)) {
console.log(`Warning: You need to pass an instance of Client:
import { Client } from "@planetscale/database";
const client = new Client({
host: process.env["DATABASE_HOST"],
username: process.env["DATABASE_USERNAME"],
password: process.env["DATABASE_PASSWORD"],
});
const db = drizzle(client);
Starting from version 0.30.0, you will encounter an error if you attempt to use anything other than a Client instance.
Please make the necessary changes now to prevent any runtime errors in the future
`);
}
const dialect = new MySqlDialect();
let logger;
if (config.logger === true) {
logger = new DefaultLogger();
} else if (config.logger !== false) {
logger = config.logger;
}
let schema;
if (config.schema) {
const tablesConfig = extractTablesRelationalConfig(
config.schema,
createTableRelationsHelpers
);
schema = {
fullSchema: config.schema,
schema: tablesConfig.tables,
tableNamesMap: tablesConfig.tableNamesMap
};
}
const session = new PlanetscaleSession(client, dialect, void 0, schema, { logger });
return new MySqlDatabase(dialect, session, schema, "planetscale");
}
export {
drizzle
};
//# sourceMappingURL=driver.js.map