How to use the bookshelf function in bookshelf

To help you get started, we’ve selected a few bookshelf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gmcdowell / bookshelf-demo / src / models / orm.js View on Github external
/**
 * 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;
github raghavgarg1257 / nodejs-mysql-boilerplate / app / db.js View on Github external
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;
github seegno / bookshelf-mask / test / index.js View on Github external
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);
  });
github seegno / bookshelf-json-columns / test / sqlite / index.js View on Github external
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);
  });
github Twilio-org / phonebank / server / routes / authenticate.js View on Github external
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' });
github Twilio-org / phonebank / server / routes / register.js View on Github external
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);
github mesaugat / express-api-es6-starter / src / db.js View on Github external
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;
github catamphetamine / webapp / code / user-service / store.js View on Github external
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)
github imheretw / imhere / src / database / index.js View on Github external
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);
github amilajack / compat-db / src / database / AbstractDatabase.js View on Github external
},
      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 };
  }