function getOldKnex(creds) { return Knex({ client: 'mysql2', connection: { host: creds.host, database: creds.database, user: creds.user, password: creds.password, port: creds.port, }, pool: { min: 2, max: 10 }, }) }
before(async () => { try { const knex = Knex({ client: 'pg', connection: { user: DB_USER, password: DB_PASS, database: DB_NAME, host: `/cloudsql/${CONNECTION_NAME}`, }, }); await knex.schema.dropTable('votes'); } catch (err) { console.log(err.message); } });
constructor(knexConfig) { super(); this.context; this.cache; if (typeof knexConfig === "function") { this.db = knexConfig; } else { this.db = Knex(knexConfig); } this.knex = this.db; const _this = this; if (!this.db.cache) { Knex.QueryBuilder.extend("cache", function(ttl) { return _this.cacheQuery(ttl, this); }); } }
function createClient (t, cb) { setup(function () { knex = Knex({ client: 'pg', connection: { database: 'test_elastic_apm', user: process.env.PGUSER || 'postgres' } }) t.on('end', () => { knex.destroy(function (err) { if (err) throw err }) knex = undefined }) cb() }) }
const connect = () => { // [START gae_flex_mysql_connect] const config = { user: process.env.SQL_USER, password: process.env.SQL_PASSWORD, database: process.env.SQL_DATABASE, }; if ( process.env.INSTANCE_CONNECTION_NAME && process.env.NODE_ENV === 'production' ) { config.socketPath = `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`; } // Connect to the database const knex = Knex({ client: 'mysql', connection: config, }); // [END gae_flex_mysql_connect] return knex; }
// Prompt the user for connection details prompt.get(FIELDS, async (err, config) => { if (err) { console.error(err); return; } // Connect to the database const knex = Knex({client: 'mysql', connection: config}); // Create the "visits" table try { await knex.schema.createTable('visits', table => { table.increments(); table.timestamp('timestamp'); table.string('userIp'); }); console.log(`Successfully created 'visits' table.`); } catch (err) { console.error(`Failed to create 'visits' table:`, err); } finally { if (knex) { knex.destroy(); } } });
const createTable = async config => { // Connect to the database config.host = `/cloudsql/${config.connectionName}`; const knex = Knex({client: 'pg', connection: config}); // Create the "votes" table try { await knex.schema.createTable('votes', table => { table.bigIncrements('vote_id').notNull(); table.timestamp('time_cast').notNull(); table.specificType('candidate', 'CHAR(6) NOT NULL'); }); console.log(`Successfully created 'votes' table.`); return knex.destroy(); } catch (err) { console.error(`Failed to create 'votes' table:`, err); if (knex) { knex.destroy(); } } }
function getKnex(conf) { switch (conf.database.client) { case 'mysql': { return Knex({ client: 'mysql2', connection: conf.database.conn, pool: { min: 2, max: 10 }, }) } case 'pg': { return Knex({ client: 'pg', version: '7.11', connection: conf.database.conn, pool: { min: 2, max: 10 }, }) } default: { return Knex({ client: 'sqlite3', useNullAsDefault: true, connection: { filename: path.join(__dirname, './db/poracle.sqlite'), }, }) } } }
const knex = Knex({ client: 'pg', connection: config,
// Prompt the user for connection details prompt.get(FIELDS, async (err, config) => { if (err) { console.error(err); return; } // Connect to the database const knex = Knex({client: 'pg', connection: config}); // Create the "visits" table try { await knex.schema.createTable('visits', table => { table.increments(); table.timestamp('timestamp'); table.string('userIp'); }); console.log(`Successfully created 'visits' table.`); return knex.destroy(); } catch (err) { console.error(`Failed to create 'visits' table:`, err); if (knex) { knex.destroy(); } } });
function getNewKnex() { switch (config.database.client) { case 'mysql': { return Knex({ client: 'mysql2', connection: config.database.conn, pool: { min: 2, max: 10 }, }) } case 'pg': { return Knex({ client: 'pg', version: '7.11', connection: config.database.conn, pool: { min: 2, max: 10 }, }) } default: { return Knex({ client: 'sqlite3', useNullAsDefault: true, connection: { filename: path.join(__dirname, '../lib/db/poracle.sqlite'), }, }) } } }