You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
994 B
35 lines
994 B
import buildKnex from "knex"
|
|
import knexConfig from "../../knexfile.mjs"
|
|
|
|
const environment = process.env.NODE_ENV || 'development';
|
|
const db = buildKnex(knexConfig[environment]);
|
|
|
|
export default db;
|
|
|
|
// async function createDatabase() {
|
|
// try {
|
|
// // SQLite会自动创建数据库文件,只需验证连接
|
|
// await db.raw("SELECT 1")
|
|
// console.log("SQLite数据库连接成功")
|
|
|
|
// // 检查users表是否存在(示例)
|
|
// const [tableExists] = await db.raw(`
|
|
// SELECT name
|
|
// FROM sqlite_master
|
|
// WHERE type='table' AND name='users'
|
|
// `)
|
|
|
|
// if (tableExists) {
|
|
// console.log("表 users 已存在")
|
|
// } else {
|
|
// console.log("表 users 不存在,需要创建(通过迁移)")
|
|
// }
|
|
|
|
// await db.destroy()
|
|
// } catch (error) {
|
|
// console.error("数据库操作失败:", error)
|
|
// process.exit(1)
|
|
// }
|
|
// }
|
|
|
|
// createDatabase()
|
|
|