mirror of
https://github.com/chatmail/core.git
synced 2026-05-15 12:56:30 +03:00
docs: document that in SQLite PRIMARY KEY should be declared with NOT NULL
This commit is contained in:
6
STYLE.md
6
STYLE.md
@@ -12,7 +12,7 @@ for example
|
|||||||
```
|
```
|
||||||
sql.execute(
|
sql.execute(
|
||||||
"CREATE TABLE messages (
|
"CREATE TABLE messages (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY NOT NULL AUTOINCREMENT,
|
||||||
text TEXT DEFAULT '' NOT NULL -- message text
|
text TEXT DEFAULT '' NOT NULL -- message text
|
||||||
) STRICT",
|
) STRICT",
|
||||||
)
|
)
|
||||||
@@ -25,7 +25,7 @@ Do not escape newlines like this:
|
|||||||
```
|
```
|
||||||
sql.execute(
|
sql.execute(
|
||||||
"CREATE TABLE messages ( \
|
"CREATE TABLE messages ( \
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
id INTEGER PRIMARY KEY NOT NULL AUTOINCREMENT, \
|
||||||
text TEXT DEFAULT '' NOT NULL \
|
text TEXT DEFAULT '' NOT NULL \
|
||||||
) STRICT",
|
) STRICT",
|
||||||
)
|
)
|
||||||
@@ -56,6 +56,8 @@ Dealing with `NULL` values both in SQL and in Rust is tricky and we try to avoid
|
|||||||
If column is already declared without `NOT NULL`, use `IFNULL` function to provide default value when selecting it.
|
If column is already declared without `NOT NULL`, use `IFNULL` function to provide default value when selecting it.
|
||||||
Use `HAVING COUNT(*) > 0` clause
|
Use `HAVING COUNT(*) > 0` clause
|
||||||
to [prevent aggregate functions such as `MIN` and `MAX` from returning `NULL`](https://stackoverflow.com/questions/66527856/aggregate-functions-max-etc-return-null-instead-of-no-rows).
|
to [prevent aggregate functions such as `MIN` and `MAX` from returning `NULL`](https://stackoverflow.com/questions/66527856/aggregate-functions-max-etc-return-null-instead-of-no-rows).
|
||||||
|
Note that in SQLite `PRIMARY KEY` does not imply `NOT NULL` for backwards compatibility,
|
||||||
|
so `PRIMARY KEY` columns should be explicitly declared as `NOT NULL`.
|
||||||
|
|
||||||
Don't delete unused columns too early, but maybe after several months/releases, unused columns are
|
Don't delete unused columns too early, but maybe after several months/releases, unused columns are
|
||||||
still used by older versions, so deleting them breaks downgrading the core or importing a backup in
|
still used by older versions, so deleting them breaks downgrading the core or importing a backup in
|
||||||
|
|||||||
Reference in New Issue
Block a user