async function insert(params) { const user = joi.attempt(params, insertSchema) return db(tableName) .insert(user) .returning('*') .then(fp.first) }
function getColumns(tableName) { return db('information_schema.columns') .where({ table_name: tableName }) .select('column_name') .options({ rowMode: 'array' }) .then(fp.map(fp.first)) }
async function insertOrReplace(params) { const contribution = joi.attempt(params, insertSchema) const query = ` INSERT INTO :tableName: ("user", repository, line_count) VALUES (:user, :repository, :line_count) ON CONFLICT ("user", repository) DO UPDATE SET line_count = :line_count RETURNING *; ` return db.raw(query, Object.assign({ tableName }, contribution)) .then(fp.first) }
/** * Get an object with {key: configueValue(key)} * @param args the keys to form object with * @returns {object} the forged object */ function getObject(...args) { const keys = args.length === 1 && Array.isArray(_.first(args)) ? _.first(args) : args; return _.reduce( (memo, key) => { const [fromKey, toKey] = Array.isArray(key) ? key : [key, key]; return _.set(toKey, this.get(fromKey), memo); }, {}, keys ); }
async function insert(params) { const contribution = joi.attempt(params, insertSchema) return db(tableName) .insert(contribution) .returning('*') .then(fp.first) }
async function insert(params) { const repository = joi.attempt(params, insertSchema) return db(tableName) .insert(repository) .returning('*') .then(fp.first) }