31 lines
981 B
TypeScript
31 lines
981 B
TypeScript
import { QueryTypes } from 'sequelize';
|
|
import { sequelize } from '../../src/modules/index.ts';
|
|
import test from 'tape';
|
|
// tsx test/db/query-table.test.ts
|
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
test('connection table', async (t) => {
|
|
try {
|
|
const auth = await sequelize.authenticate();
|
|
console.log('connect success');
|
|
} catch (error) {
|
|
console.error('connect error', error);
|
|
}
|
|
});
|
|
test('QueryTableModel:init', async (t) => {
|
|
try {
|
|
const tablesCount: any = await sequelize.query("SELECT COUNT(*) AS table_count FROM information_schema.tables WHERE table_schema = 'public';", {
|
|
type: QueryTypes.SELECT,
|
|
logging: false,
|
|
});
|
|
if (!tablesCount[0]) {
|
|
console.error('未查询到表数量');
|
|
return;
|
|
}
|
|
|
|
console.log('数据库中的表数量:', tablesCount[0].table_count);
|
|
await sleep(2000);
|
|
} catch (error) {
|
|
console.error('查询表数量时出错:', error);
|
|
}
|
|
});
|