Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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) {
}
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: {
}
var Person = db.qDefine("person", {
name : String,
surname : String,
age : Number,
male : Boolean,
continent : [ "Europe", "America", "Asia", "Africa", "Australia", "Antartica" ], // ENUM type
photo : Buffer, // BLOB/BINARY
data : Object // JSON encoded
}, {
methods: {
fullName: function () {
return this.name + ' ' + this.surname;
}
},
validations: {
age: orm.enforce.ranges.number(18, undefined, "under-age")
}
});
return Person.qAll({ surname: "Doe" })
.then(function (people) {
// SQL: "SELECT * FROM person WHERE surname = 'Doe'"
console.log("People found: %d", people.length);
console.log("First person: %s, age %d", people[0].fullName(), people[0].age);
people[0].age = 16;
return people[0].qSave()
.fail(function (err) {
console.log(err.stack);
});
});
module.exports = async () => {
let conn_url;
if(process.env.PG_URL) {
conn_url = process.env.PG_URL;
} else {
const password = process.env.PG_PASSWORD ? `:${process.env.PG_PASSWORD}` : "";
const host_with_port = process.env.PG_PORT ? `${process.env.PG_HOST}:${process.env.PG_PORT}` : process.env.PG_HOST;
conn_url = `postgres://${process.env.PG_USER}${password}@${host_with_port}/${process.env.PG_DB}`;
}
conn_url += `?pool=false`;
console.log("Postgres connection URL is: " + conn_url);
const db = await orm.connectAsync(conn_url);
// +++ Model definitions
const models = {
account: configure(require('./account')(db), db),
transaction: configure(require('./transaction')(db), db),
action: configure(require('./action')(db), db),
slackAuth: configure(require('./slack-auth')(db), db),
};
await db.syncPromise();
return models;
}
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.')
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);
});
};
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);
});
}
rebate_shop_04(query , params , sendData){
// params.plan_type = "ALL";
params.plan_name = "ALL";
params.rebate_level = "ALL";
params.rebate_type = "ALL";
params.plan_id = "ALL";
params.unique_plan_id_num = orm.gt(0);
return params;
},
rebate_shop_04_f(data, query, dates){
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(expressValidator());
app.use(cookieParser());
app.use(session({cookie: { maxAge: 60000 }, secret: 'secret'}));
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(express.static(path.join(__dirname, 'public')));
// DB configuration
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(settings.db);
orm.settings.set("instance.returnAllErrors", true);
app.use(orm.express(settings.dsn, {
define: function (db, models, next) {
db.load("./models", function (err) {
models.User = db.models.users;
models.Pad = db.models.pads;
models.Note = db.models.notes;
next();
});
}
}));
// Flash Messages configuration
app.use(function(req, res, next){
res.locals.flash_messages = {
'success': req.flash('success'),
'error': req.flash('error')
}
declParamIds,
})
const directoryId = File.create({
nameId: componentNameId,
type: DIR,
children: [
File.create({ nameId: INDEX_NAME_ID, declarationIds: [newComponentDeclarationId] }),
File.create({ nameId: wrapperNameId, type: SC, declarationIds: [wrapperDeclarationId] }),
],
})
File.withId(COMPONENTS_FILE_ID).children.insert(directoryId)
// refresh session data
orm.session({
...session.state,
})
return [
componentNameId,
newComponentDeclarationId,
wrapperInvocationId,
]
}