mirror of https://github.com/nocodb/nocodb
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.
64 lines
1.8 KiB
64 lines
1.8 KiB
2 years ago
|
import { NcContext } from '.';
|
||
2 years ago
|
const mysql = require('mysql2');
|
||
2 years ago
|
const { Client } = require('pg');
|
||
2 years ago
|
|
||
2 years ago
|
import { PromisedDatabase } from 'promised-sqlite3';
|
||
|
const sqliteDb = new PromisedDatabase();
|
||
2 years ago
|
|
||
|
const isMysql = (context: NcContext) => context.dbType === 'mysql';
|
||
|
|
||
|
const isSqlite = (context: NcContext) => context.dbType === 'sqlite';
|
||
|
|
||
|
const isPg = (context: NcContext) => context.dbType === 'pg';
|
||
|
|
||
2 years ago
|
const pg_credentials = () => ({
|
||
|
user: 'postgres',
|
||
|
host: 'localhost',
|
||
|
database: `sakila_${process.env.TEST_PARALLEL_INDEX}`,
|
||
|
password: 'password',
|
||
|
port: 5432,
|
||
|
});
|
||
|
|
||
|
const pgExec = async (query: string) => {
|
||
|
// open pg client connection
|
||
|
const client = new Client(pg_credentials());
|
||
|
await client.connect();
|
||
|
|
||
|
await client.query(query);
|
||
|
await client.end();
|
||
|
};
|
||
|
|
||
2 years ago
|
const mysqlExec = async query => {
|
||
2 years ago
|
// creates a new mysql connection using credentials from cypress.json env's
|
||
|
const connection = mysql.createConnection({
|
||
2 years ago
|
host: 'localhost',
|
||
|
user: 'root',
|
||
|
password: 'password',
|
||
|
database: `test_sakila_${process.env.TEST_PARALLEL_INDEX}`,
|
||
2 years ago
|
});
|
||
|
// start connection to db
|
||
|
connection.connect();
|
||
|
// exec query + disconnect to db as a Promise
|
||
|
return new Promise((resolve, reject) => {
|
||
|
connection.query(query, (error, results) => {
|
||
|
if (error) reject(error);
|
||
|
else {
|
||
|
connection.end();
|
||
|
// console.log(results)
|
||
|
return resolve(results);
|
||
|
}
|
||
|
});
|
||
|
});
|
||
2 years ago
|
};
|
||
2 years ago
|
|
||
|
async function sqliteExec(query) {
|
||
2 years ago
|
const parallelIndex = process.env.TEST_PARALLEL_INDEX;
|
||
|
const rootProjectDir = __dirname.replace('/scripts/playwright/setup', '');
|
||
|
await sqliteDb.open(`${rootProjectDir}/packages/nocodb/test_sakila_${parallelIndex}.db`);
|
||
|
|
||
|
await sqliteDb.run(query);
|
||
|
await sqliteDb.close();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
export { sqliteExec, mysqlExec, isMysql, isSqlite, isPg, pgExec };
|