knex .from('books') .select('title', 'author', 'year') .where({ author: 'Joe' }) .toSQL()
async tableSelect ({ table }) { const client = await knex({ client: 'pg', connection: config.env.database }); return client.select().table(table); }
db.from('capcodes') .select('id', 'ignore') // TODO: test this doesn't break other DBs - there's a lot of quote changes here .modify(function (queryBuilder) { if (dbtype == 'oracledb') { queryBuilder.whereRaw(`'${address}' LIKE "address"`) queryBuilder.orderByRaw(`REPLACE("address", '_', '%') DESC`); } else { queryBuilder.whereRaw(`"${address}" LIKE address`) queryBuilder.orderByRaw(`REPLACE(address, '_', '%') DESC`) } })
describe('legacyListMap', () => { it('converts a legacy ID to the target ID correctly', done => { db.select().from('legacy_ids').limit(1).then(legacy => { const id = legacy[0].id; const target = legacy[0].target; legacyListMap(db, id).then(test => { expect(test).to.equal(target); done(); }); }); }); });
//edit cat (cat data here includes everything we need to edit). Tip: you need the ID of cat to update otherwise //we have no idea which cat we're updating. function editOne(cat) { return db("cats") .where({ id: cat.id }) // find the cat to update .update({ name: cat.name, location: cat.location, age: cat.age }) //change the cat info to the new stuff .then(data => { return db("cats").where({ id: cat.id }); //return the cat we updated }); }
router.get('/', function(req, res) { db.select().from('todo').then(function(data) { res.send(data); }); // SELECT * FROM table_name });