Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: knex
node v8.17.0
version:
master
endpoint
share
tweet
require('sqlite3'); const Knex = require('knex'); const knexSqlite = Knex({ client: 'sqlite3', connection: { filename: ':memory:' } }); (async function run() { await knexSqlite.schema.createTable('user_category', (t) => { t.number('user_id'); t.number('category_id'); }); await knexSqlite('user_category').insert([ { user_id: 1, category_id: 2 }, { user_id: 2, category_id: 3 } ]); console.log('test table data:', await knexSqlite('user_category')); userCategories = [[2, 2], [5, 2], [8, 2], [1, 3], [2, 3], [3, 3], [7, 3]]; const query = knexSqlite('user_category').whereIn(['user_id', 'category_id'], userCategories); console.log(query.toSQL()); console.log(await query); })();
Created from: https://npm.runkit.com/knex
Loading…
no comments
sign in
to comment