Browse Source

feat(testing): Improved sqlite support

pull/3848/head
Muhammed Mustafa 2 years ago
parent
commit
7d8386c519
  1. 19
      packages/nocodb/src/lib/meta/api/testApis.ts
  2. 16
      scripts/playwright/setup/db.ts

19
packages/nocodb/src/lib/meta/api/testApis.ts

@ -1,3 +1,5 @@
import Noco from '../../Noco';
import { Request, Router } from 'express';
import { TestResetService } from '../../services/test/TestResetService';
@ -11,7 +13,24 @@ export async function reset(req: Request<any, any>, res) {
res.json(await service.process());
}
export async function sqliteExec(req: Request<any, any>, res) {
const metaKnex = Noco.ncMeta.knex;
try {
const result = await metaKnex.raw(req.body.sql);
res.json({
body: result,
});
} catch (e) {
console.error('sqliteExec', e);
res.status(500).json({
error: e,
});
}
}
const router = Router({ mergeParams: true });
router.post('/api/v1/meta/test/reset', reset);
router.post('/api/v1/meta/test/sqlite_exec', sqliteExec);
export default router;

16
scripts/playwright/setup/db.ts

@ -1,8 +1,6 @@
import { NcContext } from ".";
import { PromisedDatabase } from "promised-sqlite3";
const sqliteDb = new PromisedDatabase();
import axios from "axios";
const isMysql = (context: NcContext) => context.dbType === 'mysql';
@ -35,10 +33,14 @@ const mysqlExec = async (query) => {
}
async function sqliteExec(query) {
const rootProjectDir = __dirname.replace("/scripts/playwright/setup", "");
await sqliteDb.open(`${rootProjectDir}/packages/nocodb/test_noco.db`);
await sqliteDb.run(query);
try {
await axios.post('http://localhost:8080/api/v1/meta/test/sqlite_exec', {
"sql": query,
});
} catch (e) {
console.error(e);
throw e;
}
}
export { sqliteExec, mysqlExec, isMysql, isSqlite, isPg };
Loading…
Cancel
Save