per: https://courses.thinkful.com/auth-jwt-v1/checkpoint/2#assignment
- (RE: line 37 in things-router.js)
- The
async
andawait
keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains. - MDN: async function
- MDN: Making asynchronous programming easier with async and await
With respect to Knex, how does the transaction
method relate to BEGIN
and COMMIT
syntax in PostgreSQL?
BEGIN
initiates a transaction block, that is, all statements after a BEGIN
command will be executed in a single transaction until an explicit COMMIT
or ROLLBACK
is given. By default (without BEGIN
), PostgreSQL executes transactions in "autocommit" mode, that is, each statement is executed in its own transaction and a commit is implicitly performed at the end of the statement (if execution was successful, otherwise a rollback is done).
Statements are executed more quickly in a transaction block, because transaction start/commit requires significant CPU and disk activity. Execution of multiple statements inside a transaction is also useful to ensure consistency when making several related changes: other sessions will be unable to see the intermediate states wherein not all the related updates have been done.
💥 😕 That said, I don't see any instances in the code of a knex.transaction
method per http://knexjs.org/#Transactions ?
A sequence in PostgreSQL is a database object that is essentially an automatically incrementing numeric value. For this reason, sequences are commonly known in other database products as auto-increment values. Sequences can be extremely useful in assigning non-random, unique identification numbers to tables that require such values. A sequence consists of a current numeric value, and a set of characteristics that determine how to automatically increment (or alternatively, decrement) that value upon use.
Sequences are created with the CREATE SEQUENCE
SQL command, with various parameters.
💥 😕 This isn't explicitly used in Thinkful-server, is it? I don't see it referenced in the id
column of CREATE TABLE
?
Used in association with the TRUNCATE
psql command: RESTART IDENTITY
automatically restarts sequences owned by columns of the truncated table(s), while CASCADE
automatically truncates all tables that have foreign-key references to any of the named tables, or to any tables added to the group due to CASCADE.
src: blogful-api-auth > test.helpers.js
setval
a type of Sequence Manipulation Function. Resets the sequence object's counter value. The two-parameter form sets the sequence's last_value
field to the specified value, so in this instance it sets the last value of blogful_users_id_seq
to 1
.
id SERIAL PRIMARY KEY
-versus-
id INTEGER PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY
- wiki.postgres.org: DON'T USE SERIAL because...
- The new IDENTITY syntax conforms to the SQL standard.
- For new applications (PostgreSQL v10+), identity columns should be used instead, because serial types apparently have some weird behaviours that make schema, dependency, and permission management unnecessarily cumbersome.
- https://www.npmjs.com/package/treeize
- "Treeize takes this flattened data and based on simple column/attribute naming conventions, remaps it into a deep object graph"