How to use the orm.connect function in orm

To help you get started, we’ve selected a few orm 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 Wolox / express-js-bootstrap / app / models / scripts / tableCreation.js View on Github external
exports.execute = (DB_URL, cb) => {

  orm.connect(DB_URL, (err, db) => {

    if (err) {
      throw err;
    }

    // console.log('Connected to db!');

    models.define(orm, db);

    // add the table to the database
    db.sync((syncErr) => {
      if (syncErr) {
        throw syncErr;
      }

      if (cb) {
github unicode-org / cldr / tools / cldr-apps-watcher / routes / stwatcher.js View on Github external
}

exports._latest = function(req,res) {
    res.send("Not setup yet");
}


exports.history = function(req,res) {
    exports._history(req,res);
}

exports._history = function(req,res) {
    res.send("Not setup yet");
}

orm.connect(CONFIG.watcher.dbpath, function (orm_err, db) {
    if(orm_err) {
        console.log("Error with database: " + orm_err.toString());
        throw orm_err;
    }

    // setup DB stuff
    var HostStatus = db.define("hoststatus", {
        host      : String,
        when      : Date,
        alive     : Boolean,
        ns        : Number
    }, {
        methods: {
        },
        validations: {
        }
github teslajs / tesla.js / app / _templates / models / template.js View on Github external
module.exports = function (app) {


    var orm = require("orm"),
        tesla = require('../../lib/tesla')(app),
        teslaDB = require('../../lib/tesla.db')(app),
        enforce = require("enforce"),
        colors = require('colors'),
        db  = orm.connect(app.config.db.url);

    orm.settings.set("instance.returnAllErrors", true);

    // DEFINE MODEL SCHEMA
    // Be sure to add some files to the schema below or you will not have success quering or adding to the database
    var Model = db.define("{model}", {
        created   : { type: "date", time: true },
        updated   : { type: "date", time: true }
        // _id : { type: "text" },
        // name      : { type: "text", required: true },
        // isAdmin : { type: "boolean", defaultValue: false },
    }, {
        validations: {
            // EXAMPLE VALIDATIONS
            // password: orm.enforce.security.password('luns5', 'Passowrd does not meet min security requirements.'),
            // email: orm.enforce.patterns.email('Please enter a valid email address.')
github HiJesse / Demeter / config / DBConfig.js View on Github external
export const initORM = callback => {
    if (connection) { // 如果已经有数据库连接了, 就直接回调出去
        return callback(null, connection);
    }

    // 创建数据库连接
    orm.connect(Config.env.DB, (err, db) => {
        if (err) {
            LogUtil.e('ORM ' + err);
            return callback(err);
        }

        LogUtil.i('ORM connected');

        // 保存连接
        connection = db;
        db.settings.set('instance.returnAllErrors', true);

        // 安装models
        setup(db, callback);
    });
};
github flowgrammable / flowsim / src / candidate_for_deletion / conf / database.js View on Github external
module.exports = function (cb) {

	orm.connect(settings.database, function (err, db) {
		if (err) return cb(err);
		connection = db;

		// define models
		require('../modules/subscriber/model.js')(db, orm);
		require('../modules/profile/model.js')(db, orm);
		return cb(null, db);
	});
}
github wenqingyu / wechat-voucher-admin-system / app.js View on Github external
function init() {
    //1.连接redis
    var redis = new Redis(conf.redis, { lazyConnect: true });
    redis.on('error', function (err) {
        console.error('连接redis失败:' + err);
    })
    //全局变量db保存数据库连接
    global.db = '';
    //全局变量redis保存redis
    global.redis = redis;
    
    //2.连接数据库
    orm.connect(conf.dbString, function (err, db) {
        if (err) {
            console.error('创建数据库连接错误:' + err);
            return;
        }
        //全局保存数据库连接
        global.db = db;
        //遍历model文件夹,获取全部的model文件
        var modelList = fs.readdirSync('./model');
        //异步加载model
        Promise.map(modelList, function (model) {
            return loadModel(db, path.join(__dirname , 'model', model));
        }).then(function () {
            console.log('加载model成功');
            //3.初始化时,开启job
            var job = require('./common/schedule.js');
github dashersw / cote-workshop / models.js View on Github external
var orm = require('orm');

var connectionString;

if (process.env.PG == 'true')
    connectionString = 'postgres://cote:ohgath2ig8eoP8@postgres/cote';
else
    connectionString = 'sqlite://db.sqlite';

var db = orm.connect(connectionString, function onConnect(err) {
    if (err) {
        console.log('Error', err);
        process.exit(1);
    }
});

db.settings.set('instance.cache', false);

var Product = db.define('product', {
    name: String,
    price: Number,
    stock: Number
});

var Purchase = db.define('purchase', {});
github flowgrammable / flowsim / scratch / subscriber / tmp.js View on Github external
var orm = require('orm');
var settings = require('config/settings');
var models = require('./models');
var logic = require('./logic');

orm.connect(settings.database, function(err, db) {
  if(err) throw err;
  console.log('connected to db');

  var subscribers = models.define(db);

  var sub = {
    email: 'jasson@flowgrammable.com',
    password: '123',
    ip: '1.2.3.4'
  };

  logic.register(sub, subscribers, function(err, results) {
    if(err) throw err;
    console.log('success\n' + results);
  });

orm

NodeJS Object-relational mapping

MIT
Latest version published 10 months ago

Package Health Score

67 / 100
Full package analysis