Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if no additional arguments were provided, use the postgres connection.
It's messy, but so it goes...
*/
if (process.env.testing) {
console.log('Connecting to SQLite3 testing database...');
config = require('../../test/config/db');
} else if (process.argv[2] === 'sqlite3') {
console.log('Connecting to SQLite3 development database...');
config = require('../../config/db_sqlite');
newDB = !fs.existsSync(config.database.connection.filename);
} else {
console.log('Connecting to PostgreSQL database...');
config = require('../../config/db_pg');
}
const db = Bookshelf.initialize(config.database);
if (!process.env.testing) {
/*
When the application starts, it will check to see which migrations last ran
and run any newer migrations. This will also load some base data if this is a
new database.
*/
db.knex.migrate.latest(config).then(function () {
// if running sqlite3 in development on initial load, insert test data
if(config.database.client === "sqlite3" && newDB) {
var data = {
submissions : require('../../test/fixtures/submissions'),
submission_tags : require('../../test/fixtures/submission_tags'),
var Bookshelf = require('bookshelf');
var path = require('path');
// var SQLITE3 = require('../../creds/SQLITE3');
var db = Bookshelf.initialize({
client: 'sqlite3',
connection: {
host: process.env.SQLITE3_HOST,
user: process.env.SQLITE3_USER,
password: process.env.SQLITE3_PASSWORD,
database: process.env.SQLITE3_DATABASE,
charset: 'utf8',
filename: path.join(__dirname, 'storage/' + process.env.SQLITE3_DATABASE + '.sqlite')
}
});
db.knex.schema.hasTable('users').then(function(exists) {
if (!exists) {
db.knex.schema.createTable('users', function(user) {
user.increments('id').primary();
user.string('username',255).unique();
var
path = require('path'),
Bookshelf= require('bookshelf'),
GistcampBookshelf,
User
;
GistcampBookshelf = Bookshelf.initialize({
client: 'sqlite3',
connection: {
filename: path.join(__dirname, '/data/gistcamp-dev.db')
}
});
GistcampBookshelf.User = GistcampBookshelf.Model.extend({
tableName: 'users',
hasTimestamps: true
});
GistcampBookshelf.Tag = GistcampBookshelf.Model.extend({
});
GistcampBookshelf.Following = GistcampBookshelf.Model.extend({
var fs = require('fs-extra'),
path = require('path'),
_ = require('underscore'),
Bookshelf = require('bookshelf'),
Promise = require('bluebird'),
config = require('../config'),
errors = require('../lib/errors'),
dbConfig = config.db,
syBookshelf = module.exports = Bookshelf.initialize(dbConfig),
syModel = syBookshelf.Model,
syCollection = syBookshelf.Collection;
syModel.include({
tableName: '',
fields: [],
omitInJSON: [],
appended: [],
required: [],
validators: {},
fieldToAssets: {},
initialize: function () {
syModel.__super__.initialize.apply(this, arguments);
this._data = {};
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
var path = require('path');
var nconf = require('./config');
var conf = nconf.get('db');
conf.migrations = { directory: path.resolve(__dirname, '../migrations') };
var knex = require('knex').initialize(conf);
var bookshelf = require('bookshelf').initialize(knex);
exports.knex = knex;
exports.bookshelf = bookshelf;
exports.conf = conf;