Skip to content

Instantly share code, notes, and snippets.

@artificialarea
Last active August 12, 2020 21:35
Show Gist options
  • Save artificialarea/0e7fb264a39468a4710cac08543484e7 to your computer and use it in GitHub Desktop.
Save artificialarea/0e7fb264a39468a4710cac08543484e7 to your computer and use it in GitHub Desktop.

Thingful Q&A

per: https://courses.thinkful.com/auth-jwt-v1/checkpoint/2#assignment


Regarding Repos:


How are the syntaxes async and await useful when writing JavaScript code?


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 ?


What is a "sequence table" in PostgreSQL?

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?


What does RESTART IDENTITY CASCADE do?

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.


What does SELECT setval('blogful_users_id_seq', 1) do?

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.


PostgreSQL syntax for id fields: SERIAL vs IDENTITY?

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.

Regarding treeize dependency


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment