classes and define relationships between them • Make queries with Node’s async/await • Add validation to your models using JSON schema • Use eager-loading and transactions with your models • Work with nested documents in rows • Perform Graph Inserts and Upserts • and more…
a powerful SQL query builder. • Besides building SQL queries, Knex is used to establish database connections, including pooling connections. • Also, it is used for managing database schemas via migrations.
good pattern for managing changes to database schemas over time. • Objection.js defers to Knex for doing database migrations. • Knex depends on connecting to an existing database, so we’d need to create that first (unless it exists already).
to a database schema in a step-by-step fashion. • The “up” action applies a change (creating a table, adding or modifying a column, appending an index). • The “down” action applies the reverse action of the change (e.g. if a migration’s “up” action creates a table, it’s equivalent “down” action will drop the table). • It provides a way to evolve a database schema over time, and be able to track the state of the database schema alongside the source code in version control (Git).
it exists already) • It then creates a file in the migrations folder for the migration • The filename from the command line is prepended with a timestamp so that we can organise migrations in chronological order. • That determines the order in which migrations are executed.
They help to encapsulate the business logic within those tables (relations, validations, indexes, triggers). • Objection.js allows you to create Models using ES classes
between models that is powerful and flexible. • The relationships allow you to use other features like eager loading, as well as support Objection.js’ GraphQL plugin.
application, using Bcrypt to apply the salting and hashing. • Setting it up is very simple - simply specify the number of hashing rounds for encrypting the password, and make your User model an extended class of the Password class