0
0
Expressframework~10 mins

Knex as query builder alternative in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize Knex with a SQLite3 client.

Express
const knex = require('knex')({ client: '[1]', connection: { filename: './data.db' } });
Drag options to blanks, or click blank then click option'
Amysql
Boracle
Cpg
Dsqlite3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mysql' or 'pg' when the connection is a file path.
Forgetting to specify the client.
2fill in blank
medium

Complete the code to select all rows from the 'users' table using Knex.

Express
knex('[1]').select('*').then(rows => console.log(rows));
Drag options to blanks, or click blank then click option'
Ausers
Borders
Citems
Dproducts
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong table name like 'items' or 'orders'.
Forgetting to call select('*').
3fill in blank
hard

Fix the error in the Knex query to insert a new user with name 'Alice'.

Express
knex('[1]').insert({ name: 'Alice' }).then(() => console.log('Inserted'));
Drag options to blanks, or click blank then click option'
Auser
Buser_table
Cusers
Daccounts
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'user' instead of 'users'.
Using unrelated table names.
4fill in blank
hard

Fill both blanks to update the email of user with id 5 to 'new@example.com'.

Express
knex('[1]').where('[2]', 5).update({ email: 'new@example.com' }).then(() => console.log('Updated'));
Drag options to blanks, or click blank then click option'
Ausers
Bid
Cemail
Dusername
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong table names like 'email' or 'username' as table.
Filtering by 'email' instead of 'id'.
5fill in blank
hard

Fill all three blanks to delete users older than 30 from the 'users' table.

Express
knex('[1]').where('[2]', '[3]', 30).del().then(() => console.log('Deleted'));
Drag options to blanks, or click blank then click option'
Ausers
Bage
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong table names.
Using '<' instead of '>' for age comparison.