Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* Created by greg on 27/04/15.
*/
import Knex from 'knex';
import Bookshelf from 'bookshelf';
import Config from '../../knexfile';
const Orm = new Bookshelf(new Knex(Config.development));
// enable Bookshelf plugins
Orm.plugin('registry');
Orm.plugin('virtuals');
Orm.plugin('visibility');
export default Orm;
import dotenv from "dotenv";
dotenv.config();
const knex = _knex({
client: "mysql",
connection: {
host: "127.0.0.1",
database: process.env.DB,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD
},
debug: true
});
const Bookshelf = _bookshelf(knex);
// to resolve circular dependencies with relations
Bookshelf.plugin('registry');
export default Bookshelf;
describe('bookshelf-mask', () => {
const repository = bookshelf(knex(knexfile));
repository.plugin(['virtuals', mask]);
const { Author, Post } = fixtures(repository);
before(async () => {
await recreateTables(repository);
});
afterEach(async () => {
await clearTables(repository);
});
after(async () => {
await dropTables(repository);
});
describe('with SQLite client', () => {
const repository = bookshelf(knex(knexfile));
const CollectionPrototype = repository.Collection.prototype;
const ModelPrototype = repository.Model.prototype;
repository.plugin(jsonColumns);
before(async () => {
await recreateTable(repository);
});
afterEach(async () => {
await clearTable(repository);
});
after(async () => {
await dropTable(repository);
});
import express from 'express';
import bcrypt from 'bcrypt';
import genToken from '../config/auth/jwtGenerator';
import User from '../db/controllers/users';
import knexModule from 'knex';
import bookshelfModule from 'bookshelf';
import { development as devconfig } from '../../knexfile';
import bookshelfBcrypt from 'bookshelf-bcrypt';
const { bookshelf } = require('../db/init').default;
const knex = knexModule(devconfig);
const knexdb = bookshelfModule(knex);
let usersModel = require('../db/models/users').default;
knexdb.plugin(bookshelfBcrypt);
usersModel = usersModel(knexdb);
const router = express.Router();
router.post('/', (req, res) => {
const reqEmail = req.body.email;
const reqPassword = req.body.password;
if (reqEmail && reqPassword) {
User.getUserByEmail({ email: reqEmail }, usersModel)
.then((user) => {
if (!user) {
console.log('user not found');
res.status(401).send({ message: 'invalid username or password' });
import express from 'express';
import { development as devconfig } from '../../knexfile';
import knexModule from 'knex';
import bookshelfModule from 'bookshelf';
import bookshelfBcrypt from 'bookshelf-bcrypt';
import User from '../db/controllers/users';
import Model from '../db/models/users';
const knex = knexModule(devconfig);
const knexdb = bookshelfModule(knex).plugin(bookshelfBcrypt);
const usersModel = Model(knexdb);
const router = express.Router();
router.post('/', (req, res) => {
const userParams = req.body;
User.saveNewUser(userParams, usersModel)
.then((user) => {
if (user) {
res.status(201).json({ message: 'Registration Successful' });
}
})
.catch((err) => {
console.log(err);
import knexJs from 'knex';
import bookshelfJs from 'bookshelf';
import knexConfig from './knexfile';
/**
* Database connection.
*/
const knex = knexJs(knexConfig);
const bookshelf = bookshelfJs(knex);
bookshelf.plugin(['bookshelf-virtuals-plugin']);
export default bookshelf;
function create_store()
{
if (!fs.existsSync(path.join(Root_folder, 'knexfile.js')))
{
log.info('PostgreSQL connection is not configured. Using in-memory store.')
return new Memory_store()
}
log.info(`Connecting to PostgreSQL`)
log.info('(in case of failure with throw ECONNRESET)')
const knex = Knex(require(path.join(Root_folder, 'knexfile')))
const bookshelf = Bookshelf(knex)
const User = bookshelf.Model.extend
({
tableName : 'users'
})
const Message = bookshelf.Model.extend
({
tableName : 'messages',
from : () => this.belongsTo(User),
to : () => this.belongsTo(User)
})
const store =
{
create_user(user)
import Bookshelf from 'bookshelf';
import modelBase from 'bookshelf-modelbase';
import Schema from 'bookshelf-schema';
import knex from 'knex';
import dbConfig from 'config/knexConfig';
const environment = process.env.NODE_ENV || 'development';
const config = dbConfig[environment];
const connection = knex(config);
const _bookshelf = Bookshelf(connection);
_bookshelf.plugin('pagination');
_bookshelf.plugin(Schema());
_bookshelf.plugin(modelBase.pluggable);
export const bookshelf = _bookshelf;
export const ModelBase = modelBase(bookshelf);
},
acquireConnectionTimeout: 1000000
};
const sqliteConfig = {
client: 'sqlite3',
useNullAsDefault: true,
connection: {
filename: join(__dirname, 'database.sqlite')
}
};
const knex = Knex(
process.env.USE_SQLITE === 'false' ? mysqlConfig : sqliteConfig
);
const Bookshelf = bookshelf(knex);
const Database = Bookshelf.Model.extend({ tableName: this.tableName });
return { knex, Database, Bookshelf };
}