better-sqlite3
Advanced tools
Comparing version 0.6.0 to 0.6.1
{ | ||
"name": "better-sqlite3", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Simple and expressive SQLite3 bindings for Node.js, with full transaction support.", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/JoshuaWise/better-sqlite3", |
@@ -33,2 +33,2 @@ # better-sqlite3 | ||
[MIT](https://github.com/JoshuaWise/better-sqlite3/blob/master/LICENSE.md). | ||
[MIT](https://github.com/JoshuaWise/better-sqlite3/blob/master/LICENSE.md) |
19
TIPS.md
@@ -1,7 +0,8 @@ | ||
## Creating safe tables | ||
# Helpful tips for SQLite3 | ||
## Creating good tables | ||
It's a good idea to use `INTEGER PRIMARY KEY AUTOINCREMENT` as one of the columns in a table. This ensures two things: | ||
- `INTEGER PRIMARY KEY`: improved performance by reusing SQLite3's built-in `rowid` column | ||
- `INTEGER PRIMARY KEY`: improved performance by reusing SQLite3's built-in `rowid` column. | ||
- `AUTOINCREMENT`: no future row will have the same ID as an old one that was deleted. This can prevent potential bugs and security breaches. | ||
If you *don't* use `INTEGER PRIMARY KEY`, then you *must* use `NOT NULL` in all of your your primary key columns. Otherwise you'll be victim to an SQLite3 bug that allows primary keys to be `NULL`. | ||
If you don't use `INTEGER PRIMARY KEY`, then you *must* use `NOT NULL` in all of your your primary key columns. Otherwise you'll be victim to an SQLite3 bug that allows primary keys to be `NULL`. | ||
@@ -20,11 +21,11 @@ Any column with `INTEGER PRIMARY KEY` will automatically increment when setting its value to `NULL`. But without `AUTOINCREMENT`, the behavior only ensures uniqueness from currently existing rows. | ||
```sql | ||
CREATE TABLE ages (age INTEGER, person_id INTEGER NOT NULL REFERENCES people); | ||
CREATE TABLE comments (value TEXT, user_id INTEGER NOT NULL REFERENCES users); | ||
``` | ||
Foreign key clauses can be followed by `ON DELETE` and/or `ON UPDATE`, with the following possible values: | ||
- `SET NULL`: if the parent column is deleted or updated, the child column becomes `NULL` | ||
- *This still causes a constraint violation if the child column has `NOT NULL`* | ||
- `SET DEFAULT`: if the parent column is updated or deleted, the child column becomes its `DEFAULT` value | ||
- *This still causes a constraint violation if the child column's `DEFAULT` value does not correspond with an actual parent row* | ||
- `CASCADE`: if the parent row is deleted, the child row is deleted; if the parent column is updated, the new value is propogated to all children | ||
- `SET NULL`: if the parent column is deleted or updated, the child column becomes `NULL`. | ||
- *NOTE: This still causes a constraint violation if the child column has `NOT NULL`*. | ||
- `SET DEFAULT`: if the parent column is updated or deleted, the child column becomes its `DEFAULT` value. | ||
- *NOTE: This still causes a constraint violation if the child column's `DEFAULT` value does not correspond with an actual parent row*. | ||
- `CASCADE`: if the parent row is deleted, the child row is deleted; if the parent column is updated, the new value is propogated to the child column. | ||
11249022