bump: 依赖修改
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
import { QueryTypes } from 'sequelize';
|
||||
import { RouterCodeModel } from '../../src/models/code.ts';
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
// yarn test --testNamePattern='RouterCodeModel'
|
||||
describe('RouterCodeModel', () => {
|
||||
// 编写一个测试用例
|
||||
// yarn test --testNamePattern='RouterCodeModel:init'
|
||||
test('RouterCodeModel:init', async () => {
|
||||
try {
|
||||
RouterCodeModel.sync({ force: true });
|
||||
console.log('connect success');
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('connect error', error);
|
||||
}
|
||||
});
|
||||
// yarn test --testNamePattern='RouterCodeModel:sync'
|
||||
test('RouterCodeModel:sync', async () => {
|
||||
try {
|
||||
RouterCodeModel.sync({ alter: true });
|
||||
console.log('connect success');
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('connect error', error);
|
||||
}
|
||||
});
|
||||
// yarn test --testNamePattern='RouterCodeModel:create'
|
||||
test('RouterCodeModel:create', async () => {
|
||||
try {
|
||||
const demoCode = `async function run(ctx) {
|
||||
ctx.body = 'test js';
|
||||
return ctx;
|
||||
}`;
|
||||
const file = await RouterCodeModel.create({
|
||||
path: 'demo',
|
||||
key: 'returnDemo',
|
||||
active: true,
|
||||
project: 'default',
|
||||
code: demoCode,
|
||||
exec: demoCode,
|
||||
});
|
||||
console.log('create success', file);
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('create error', error);
|
||||
}
|
||||
});
|
||||
// yarn test --testNamePattern='RouterCodeModel:findAll'
|
||||
test('RouterCodeModel:findAll', async () => {
|
||||
try {
|
||||
const files = await RouterCodeModel.findAll();
|
||||
console.log(
|
||||
'findAll success',
|
||||
files.map((file) => file.toJSON()),
|
||||
);
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('findAll error', error);
|
||||
}
|
||||
});
|
||||
});
|
@@ -1,36 +0,0 @@
|
||||
import { QueryTypes } from 'sequelize';
|
||||
import { sequelize } from '../../src/modules/index.ts';
|
||||
|
||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
// yarn test --testNamePattern='Sequelize'
|
||||
describe('Hello Sequelize', () => {
|
||||
// 编写一个测试用例
|
||||
// yarn test --testNamePattern='Sequelize:connect success'
|
||||
test('Sequelize:connect success', async () => {
|
||||
try {
|
||||
const auth = await sequelize.authenticate();
|
||||
console.log('connect success');
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('connect error', error);
|
||||
}
|
||||
});
|
||||
// yarn test --testNamePattern='Sequelize:queryTables'
|
||||
test('Sequelize:queryTables', async () => {
|
||||
try {
|
||||
const tablesCount: any = await sequelize.query(
|
||||
"SELECT COUNT(*) AS table_count FROM information_schema.tables WHERE table_schema = 'public';",
|
||||
{ type: QueryTypes.SELECT },
|
||||
);
|
||||
if (!tablesCount[0]) {
|
||||
console.error('未查询到表数量');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('数据库中的表数量:', tablesCount[0].table_count);
|
||||
await sleep(2000);
|
||||
} catch (error) {
|
||||
console.error('查询表数量时出错:', error);
|
||||
}
|
||||
});
|
||||
});
|
30
test/db/query-table.test.ts
Normal file
30
test/db/query-table.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user