From 56e4e2d518f08fb4ac37f37590bb122dd16839d1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 9 Jan 2021 14:08:55 +1000 Subject: [PATCH] reformat .sql files --- rslib/src/media/schema.sql | 21 ++- rslib/src/search/deck_order.sql | 18 +- rslib/src/search/notetype_order.sql | 18 +- rslib/src/search/template_order.sql | 22 ++- rslib/src/storage/card/add_card.sql | 25 ++- rslib/src/storage/card/add_or_update.sql | 7 +- .../src/storage/card/at_or_above_position.sql | 10 +- rslib/src/storage/card/congrats.sql | 56 +++--- rslib/src/storage/card/fix_due_new.sql | 30 ++-- rslib/src/storage/card/fix_due_other.sql | 28 ++- rslib/src/storage/card/fix_ivl.sql | 8 +- rslib/src/storage/card/fix_low_ease.sql | 20 +-- rslib/src/storage/card/fix_odue.sql | 36 ++-- rslib/src/storage/card/get_card.sql | 9 +- rslib/src/storage/card/search_cids_setup.sql | 4 +- .../card/search_cids_setup_ordered.sql | 4 +- rslib/src/storage/card/update_card.sql | 8 +- rslib/src/storage/config/add.sql | 7 +- rslib/src/storage/config/get.sql | 8 +- rslib/src/storage/deck/alloc_id.sql | 21 +-- rslib/src/storage/deck/cards_for_deck.sql | 12 +- rslib/src/storage/deck/due_counts.sql | 40 ++--- rslib/src/storage/deck/get_deck.sql | 5 +- rslib/src/storage/deck/missing-decks.sql | 13 +- rslib/src/storage/deck/update_active.sql | 16 +- rslib/src/storage/deck/update_deck.sql | 7 +- rslib/src/storage/deckconf/add.sql | 25 ++- rslib/src/storage/deckconf/add_or_update.sql | 7 +- rslib/src/storage/deckconf/get.sql | 5 +- rslib/src/storage/deckconf/update.sql | 8 +- rslib/src/storage/graves/add.sql | 7 +- rslib/src/storage/note/add.sql | 25 ++- rslib/src/storage/note/add_or_update.sql | 7 +- rslib/src/storage/note/get.sql | 5 +- rslib/src/storage/note/is_orphaned.sql | 8 +- rslib/src/storage/note/update.sql | 8 +- rslib/src/storage/notetype/add_notetype.sql | 25 ++- rslib/src/storage/notetype/add_or_update.sql | 7 +- .../notetype/delete_cards_for_template.sql | 15 +- rslib/src/storage/notetype/existing_cards.sql | 29 ++-- .../notetype/field_names_for_notes.sql | 16 +- rslib/src/storage/notetype/get_fields.sql | 11 +- rslib/src/storage/notetype/get_notetype.sql | 5 +- .../storage/notetype/get_notetype_names.sql | 5 +- rslib/src/storage/notetype/get_templates.sql | 11 +- rslib/src/storage/notetype/get_use_counts.sql | 16 +- .../src/storage/notetype/highest_card_ord.sql | 14 +- rslib/src/storage/notetype/update_fields.sql | 5 +- .../notetype/update_notetype_config.sql | 7 +- .../storage/notetype/update_notetype_core.sql | 7 +- .../src/storage/notetype/update_templates.sql | 5 +- rslib/src/storage/revlog/add.sql | 24 +-- rslib/src/storage/revlog/fix_props.sql | 10 +- rslib/src/storage/revlog/get.sql | 5 +- rslib/src/storage/revlog/studied_today.sql | 10 +- rslib/src/storage/schema11.sql | 160 +++++++++--------- rslib/src/storage/tag/add.sql | 7 +- .../storage/upgrades/schema11_downgrade.sql | 23 ++- .../src/storage/upgrades/schema14_upgrade.sql | 33 ++-- .../src/storage/upgrades/schema15_upgrade.sql | 80 +++++---- 60 files changed, 505 insertions(+), 583 deletions(-) diff --git a/rslib/src/media/schema.sql b/rslib/src/media/schema.sql index 236ebe216..d25dbb040 100644 --- a/rslib/src/media/schema.sql +++ b/rslib/src/media/schema.sql @@ -1,10 +1,13 @@ -create table media ( - fname text not null primary key, - csum text, -- null indicates deleted file - mtime int not null, -- zero if deleted - dirty int not null +CREATE TABLE media ( + fname text NOT NULL PRIMARY KEY, + csum text, + -- null indicates deleted file + mtime int NOT NULL, + -- zero if deleted + dirty int NOT NULL ) without rowid; - -create index idx_media_dirty on media (dirty) where dirty=1; - -create table meta (dirMod int, lastUsn int); insert into meta values (0, 0); +CREATE INDEX idx_media_dirty ON media (dirty) +WHERE dirty = 1; +CREATE TABLE meta (dirMod int, lastUsn int); +INSERT INTO meta +VALUES (0, 0); \ No newline at end of file diff --git a/rslib/src/search/deck_order.sql b/rslib/src/search/deck_order.sql index 9a679195b..823f6dada 100644 --- a/rslib/src/search/deck_order.sql +++ b/rslib/src/search/deck_order.sql @@ -1,11 +1,9 @@ -drop table if exists sort_order; -create temporary table sort_order ( - pos integer primary key, - did integer not null unique +DROP TABLE IF EXISTS sort_order; +CREATE TEMPORARY TABLE sort_order ( + pos integer PRIMARY KEY, + did integer NOT NULL UNIQUE ); -insert into sort_order (did) -select - id -from decks -order by - name; \ No newline at end of file +INSERT INTO sort_order (did) +SELECT id +FROM decks +ORDER BY name; \ No newline at end of file diff --git a/rslib/src/search/notetype_order.sql b/rslib/src/search/notetype_order.sql index 756418ec8..a5e07b086 100644 --- a/rslib/src/search/notetype_order.sql +++ b/rslib/src/search/notetype_order.sql @@ -1,11 +1,9 @@ -drop table if exists sort_order; -create temporary table sort_order ( - pos integer primary key, - ntid integer not null unique +DROP TABLE IF EXISTS sort_order; +CREATE TEMPORARY TABLE sort_order ( + pos integer PRIMARY KEY, + ntid integer NOT NULL UNIQUE ); -insert into sort_order (ntid) -select - id -from notetypes -order by - name; \ No newline at end of file +INSERT INTO sort_order (ntid) +SELECT id +FROM notetypes +ORDER BY name; \ No newline at end of file diff --git a/rslib/src/search/template_order.sql b/rslib/src/search/template_order.sql index c120b24bb..96b7ecd1d 100644 --- a/rslib/src/search/template_order.sql +++ b/rslib/src/search/template_order.sql @@ -1,14 +1,12 @@ -drop table if exists sort_order; -create temporary table sort_order ( - pos integer primary key, - ntid integer not null, - ord integer not null, - unique(ntid, ord) +DROP TABLE IF EXISTS sort_order; +CREATE TEMPORARY TABLE sort_order ( + pos integer PRIMARY KEY, + ntid integer NOT NULL, + ord integer NOT NULL, + UNIQUE(ntid, ord) ); -insert into sort_order (ntid, ord) -select - ntid, +INSERT INTO sort_order (ntid, ord) +SELECT ntid, ord -from templates -order by - name \ No newline at end of file +FROM templates +ORDER BY name \ No newline at end of file diff --git a/rslib/src/storage/card/add_card.sql b/rslib/src/storage/card/add_card.sql index 5da46ac1f..659723648 100644 --- a/rslib/src/storage/card/add_card.sql +++ b/rslib/src/storage/card/add_card.sql @@ -1,4 +1,4 @@ -insert into cards ( +INSERT INTO cards ( id, nid, did, @@ -18,21 +18,18 @@ insert into cards ( flags, data ) -values - ( +VALUES ( ( - case - when ?1 in ( - select - id - from cards - ) then ( - select - max(id) + 1 - from cards + CASE + WHEN ?1 IN ( + SELECT id + FROM cards + ) THEN ( + SELECT max(id) + 1 + FROM cards ) - else ?1 - end + ELSE ?1 + END ), ?, ?, diff --git a/rslib/src/storage/card/add_or_update.sql b/rslib/src/storage/card/add_or_update.sql index 641e0de18..646ce3595 100644 --- a/rslib/src/storage/card/add_or_update.sql +++ b/rslib/src/storage/card/add_or_update.sql @@ -1,5 +1,5 @@ -insert - or replace into cards ( +INSERT + OR REPLACE INTO cards ( id, nid, did, @@ -19,8 +19,7 @@ insert flags, data ) -values - ( +VALUES ( ?, ?, ?, diff --git a/rslib/src/storage/card/at_or_above_position.sql b/rslib/src/storage/card/at_or_above_position.sql index 2621aa55a..73ed0f475 100644 --- a/rslib/src/storage/card/at_or_above_position.sql +++ b/rslib/src/storage/card/at_or_above_position.sql @@ -1,5 +1,5 @@ -insert into search_cids -select id -from cards -where due >= ? - and type = ? \ No newline at end of file +INSERT INTO search_cids +SELECT id +FROM cards +WHERE due >= ? + AND type = ? \ No newline at end of file diff --git a/rslib/src/storage/card/congrats.sql b/rslib/src/storage/card/congrats.sql index b62d8cc81..e720feb04 100644 --- a/rslib/src/storage/card/congrats.sql +++ b/rslib/src/storage/card/congrats.sql @@ -1,28 +1,28 @@ -select coalesce( - sum( - queue in (:review_queue, :day_learn_queue) - and due <= :today - ), - 0 - ) as review_count, - coalesce(sum(queue = :new_queue), 0) as new_count, - coalesce(sum(queue = :sched_buried_queue), 0) as sched_buried, - coalesce(sum(queue = :user_buried_queue), 0) as user_buried, - coalesce(sum(queue = :learn_queue), 0) as learn_count, - max( - 0, - coalesce( - min( - case - when queue = :learn_queue then due - else null - end - ), - 0 - ) - ) as first_learn_due -from cards -where did in ( - select id - from active_decks - ) \ No newline at end of file +SELECT coalesce( + sum( + queue IN (:review_queue, :day_learn_queue) + AND due <= :today + ), + 0 + ) AS review_count, + coalesce(sum(queue = :new_queue), 0) AS new_count, + coalesce(sum(queue = :sched_buried_queue), 0) AS sched_buried, + coalesce(sum(queue = :user_buried_queue), 0) AS user_buried, + coalesce(sum(queue = :learn_queue), 0) AS learn_count, + max( + 0, + coalesce( + min( + CASE + WHEN queue = :learn_queue THEN due + ELSE NULL + END + ), + 0 + ) + ) AS first_learn_due +FROM cards +WHERE did IN ( + SELECT id + FROM active_decks + ) \ No newline at end of file diff --git a/rslib/src/storage/card/fix_due_new.sql b/rslib/src/storage/card/fix_due_new.sql index d24f9fad4..327c5522e 100644 --- a/rslib/src/storage/card/fix_due_new.sql +++ b/rslib/src/storage/card/fix_due_new.sql @@ -1,20 +1,18 @@ -update cards -set - due = ( - case - when type = 0 - and queue != 4 then 1000000 + due % 1000000 - else due - end +UPDATE cards +SET due = ( + CASE + WHEN type = 0 + AND queue != 4 THEN 1000000 + due % 1000000 + ELSE due + END ), mod = ?1, usn = ?2 -where - due != ( - case - when type = 0 - and queue != 4 then 1000000 + due % 1000000 - else due - end +WHERE due != ( + CASE + WHEN type = 0 + AND queue != 4 THEN 1000000 + due % 1000000 + ELSE due + END ) - and due >= 1000000; \ No newline at end of file + AND due >= 1000000; \ No newline at end of file diff --git a/rslib/src/storage/card/fix_due_other.sql b/rslib/src/storage/card/fix_due_other.sql index 8d71c1941..6c072e5b2 100644 --- a/rslib/src/storage/card/fix_due_other.sql +++ b/rslib/src/storage/card/fix_due_other.sql @@ -1,19 +1,17 @@ -update cards -set - due = ( - case - when queue = 2 - and due > 100000 then ?1 - else min(max(round(due), -2147483648), 2147483647) - end +UPDATE cards +SET due = ( + CASE + WHEN queue = 2 + AND due > 100000 THEN ?1 + ELSE min(max(round(due), -2147483648), 2147483647) + END ), mod = ?2, usn = ?3 -where - due != ( - case - when queue = 2 - and due > 100000 then ?1 - else min(max(round(due), -2147483648), 2147483647) - end +WHERE due != ( + CASE + WHEN queue = 2 + AND due > 100000 THEN ?1 + ELSE min(max(round(due), -2147483648), 2147483647) + END ); \ No newline at end of file diff --git a/rslib/src/storage/card/fix_ivl.sql b/rslib/src/storage/card/fix_ivl.sql index a77c1793b..d8a1894be 100644 --- a/rslib/src/storage/card/fix_ivl.sql +++ b/rslib/src/storage/card/fix_ivl.sql @@ -1,7 +1,5 @@ -update cards -set - ivl = min(max(round(ivl), 0), 2147483647), +UPDATE cards +SET ivl = min(max(round(ivl), 0), 2147483647), mod = ?1, usn = ?2 -where - ivl != min(max(round(ivl), 0), 2147483647) \ No newline at end of file +WHERE ivl != min(max(round(ivl), 0), 2147483647) \ No newline at end of file diff --git a/rslib/src/storage/card/fix_low_ease.sql b/rslib/src/storage/card/fix_low_ease.sql index d905613d0..23e5a97e4 100644 --- a/rslib/src/storage/card/fix_low_ease.sql +++ b/rslib/src/storage/card/fix_low_ease.sql @@ -1,10 +1,10 @@ -update cards -set factor = 2500, - usn = ?, - mod = ? -where factor != 0 - and factor <= 2000 - and ( - did in DECK_IDS - or odid in DECK_IDS - ) \ No newline at end of file +UPDATE cards +SET factor = 2500, + usn = ?, + mod = ? +WHERE factor != 0 + AND factor <= 2000 + AND ( + did IN DECK_IDS + OR odid IN DECK_IDS + ) \ No newline at end of file diff --git a/rslib/src/storage/card/fix_odue.sql b/rslib/src/storage/card/fix_odue.sql index dc121333e..87b636984 100644 --- a/rslib/src/storage/card/fix_odue.sql +++ b/rslib/src/storage/card/fix_odue.sql @@ -1,27 +1,25 @@ -update cards -set - odue = ( - case - when odue > 0 - and ( +UPDATE cards +SET odue = ( + CASE + WHEN odue > 0 + AND ( type = 1 - or queue = 2 + OR queue = 2 ) - and not odid then 0 - else min(max(round(odue), -2147483648), 2147483647) - end + AND NOT odid THEN 0 + ELSE min(max(round(odue), -2147483648), 2147483647) + END ), mod = ?1, usn = ?2 -where - odue != ( - case - when odue > 0 - and ( +WHERE odue != ( + CASE + WHEN odue > 0 + AND ( type = 1 - or queue = 2 + OR queue = 2 ) - and not odid then 0 - else min(max(round(odue), -2147483648), 2147483647) - end + AND NOT odid THEN 0 + ELSE min(max(round(odue), -2147483648), 2147483647) + END ); \ No newline at end of file diff --git a/rslib/src/storage/card/get_card.sql b/rslib/src/storage/card/get_card.sql index 227c925ab..0ba5d9b89 100644 --- a/rslib/src/storage/card/get_card.sql +++ b/rslib/src/storage/card/get_card.sql @@ -1,14 +1,13 @@ -select - id, +SELECT id, nid, did, ord, - cast(mod as integer), + cast(mod AS integer), usn, type, queue, due, - cast(ivl as integer), + cast(ivl AS integer), factor, reps, lapses, @@ -17,4 +16,4 @@ select odid, flags, data -from cards \ No newline at end of file +FROM cards \ No newline at end of file diff --git a/rslib/src/storage/card/search_cids_setup.sql b/rslib/src/storage/card/search_cids_setup.sql index 485b63ec7..7da26c813 100644 --- a/rslib/src/storage/card/search_cids_setup.sql +++ b/rslib/src/storage/card/search_cids_setup.sql @@ -1,2 +1,2 @@ -drop table if exists search_cids; -create temporary table search_cids (cid integer primary key not null); \ No newline at end of file +DROP TABLE IF EXISTS search_cids; +CREATE TEMPORARY TABLE search_cids (cid integer PRIMARY KEY NOT NULL); \ No newline at end of file diff --git a/rslib/src/storage/card/search_cids_setup_ordered.sql b/rslib/src/storage/card/search_cids_setup_ordered.sql index 34cb16647..e3671338d 100644 --- a/rslib/src/storage/card/search_cids_setup_ordered.sql +++ b/rslib/src/storage/card/search_cids_setup_ordered.sql @@ -1,2 +1,2 @@ -drop table if exists search_cids; -create temporary table search_cids (cid integer not null); \ No newline at end of file +DROP TABLE IF EXISTS search_cids; +CREATE TEMPORARY TABLE search_cids (cid integer NOT NULL); \ No newline at end of file diff --git a/rslib/src/storage/card/update_card.sql b/rslib/src/storage/card/update_card.sql index 3c0f6bfc1..8a9a68531 100644 --- a/rslib/src/storage/card/update_card.sql +++ b/rslib/src/storage/card/update_card.sql @@ -1,6 +1,5 @@ -update cards -set - nid = ?, +UPDATE cards +SET nid = ?, did = ?, ord = ?, mod = ?, @@ -17,5 +16,4 @@ set odid = ?, flags = ?, data = ? -where - id = ? \ No newline at end of file +WHERE id = ? \ No newline at end of file diff --git a/rslib/src/storage/config/add.sql b/rslib/src/storage/config/add.sql index a0663035c..16531c36e 100644 --- a/rslib/src/storage/config/add.sql +++ b/rslib/src/storage/config/add.sql @@ -1,4 +1,3 @@ -insert - or replace into config (key, usn, mtime_secs, val) -values - (?, ?, ?, ?) \ No newline at end of file +INSERT + OR REPLACE INTO config (KEY, usn, mtime_secs, val) +VALUES (?, ?, ?, ?) \ No newline at end of file diff --git a/rslib/src/storage/config/get.sql b/rslib/src/storage/config/get.sql index ae7ca50a6..73a86c2df 100644 --- a/rslib/src/storage/config/get.sql +++ b/rslib/src/storage/config/get.sql @@ -1,5 +1,3 @@ -select - val -from config -where - key = ? \ No newline at end of file +SELECT val +FROM config +WHERE KEY = ? \ No newline at end of file diff --git a/rslib/src/storage/deck/alloc_id.sql b/rslib/src/storage/deck/alloc_id.sql index 80004ad56..ec3512702 100644 --- a/rslib/src/storage/deck/alloc_id.sql +++ b/rslib/src/storage/deck/alloc_id.sql @@ -1,13 +1,10 @@ -select - case - when ?1 in ( - select - id - from decks - ) then ( - select - max(id) + 1 - from decks +SELECT CASE + WHEN ?1 IN ( + SELECT id + FROM decks + ) THEN ( + SELECT max(id) + 1 + FROM decks ) - else ?1 - end; \ No newline at end of file + ELSE ?1 + END; \ No newline at end of file diff --git a/rslib/src/storage/deck/cards_for_deck.sql b/rslib/src/storage/deck/cards_for_deck.sql index 6c9cfb1f3..973affc28 100644 --- a/rslib/src/storage/deck/cards_for_deck.sql +++ b/rslib/src/storage/deck/cards_for_deck.sql @@ -1,9 +1,7 @@ -select - id -from cards -where - did = ?1 - or ( +SELECT id +FROM cards +WHERE did = ?1 + OR ( odid != 0 - and odid = ?1 + AND odid = ?1 ) \ No newline at end of file diff --git a/rslib/src/storage/deck/due_counts.sql b/rslib/src/storage/deck/due_counts.sql index 5d94aeee7..f93be6523 100644 --- a/rslib/src/storage/deck/due_counts.sql +++ b/rslib/src/storage/deck/due_counts.sql @@ -1,41 +1,41 @@ -select did, +SELECT did, sum(queue = :new_queue), sum( queue = :review_queue - and due <= :day_cutoff + AND due <= :day_cutoff ), -- learning sum( ( - case + CASE :sched_ver - when 2 then ( + WHEN 2 THEN ( -- v2 scheduler ( queue = :learn_queue - and due < :learn_cutoff + AND due < :learn_cutoff ) - or ( + OR ( queue = :daylearn_queue - and due <= :day_cutoff + AND due <= :day_cutoff ) - or ( + OR ( queue = :preview_queue - and due <= :learn_cutoff + AND due <= :learn_cutoff ) ) - else ( + ELSE ( -- v1 scheduler - case - when queue = :learn_queue - and due < :learn_cutoff then left / 1000 - when queue = :daylearn_queue - and due <= :day_cutoff then 1 - else 0 - end + CASE + WHEN queue = :learn_queue + AND due < :learn_cutoff THEN left / 1000 + WHEN queue = :daylearn_queue + AND due <= :day_cutoff THEN 1 + ELSE 0 + END ) - end + END ) ) -from cards -where queue >= 0 \ No newline at end of file +FROM cards +WHERE queue >= 0 \ No newline at end of file diff --git a/rslib/src/storage/deck/get_deck.sql b/rslib/src/storage/deck/get_deck.sql index b456367b5..8afd87aa1 100644 --- a/rslib/src/storage/deck/get_deck.sql +++ b/rslib/src/storage/deck/get_deck.sql @@ -1,8 +1,7 @@ -select - id, +SELECT id, name, mtime_secs, usn, common, kind -from decks \ No newline at end of file +FROM decks \ No newline at end of file diff --git a/rslib/src/storage/deck/missing-decks.sql b/rslib/src/storage/deck/missing-decks.sql index dfba53afc..e2c79691c 100644 --- a/rslib/src/storage/deck/missing-decks.sql +++ b/rslib/src/storage/deck/missing-decks.sql @@ -1,9 +1,6 @@ -select - distinct did -from cards -where - did not in ( - select - id - from decks +SELECT DISTINCT did +FROM cards +WHERE did NOT IN ( + SELECT id + FROM decks ); \ No newline at end of file diff --git a/rslib/src/storage/deck/update_active.sql b/rslib/src/storage/deck/update_active.sql index 54f49bf7f..7da982e47 100644 --- a/rslib/src/storage/deck/update_active.sql +++ b/rslib/src/storage/deck/update_active.sql @@ -1,8 +1,8 @@ -insert into active_decks -select id -from decks -where name = ? - or ( - name >= ? - and name < ? - ) \ No newline at end of file +INSERT INTO active_decks +SELECT id +FROM decks +WHERE name = ? + OR ( + name >= ? + AND name < ? + ) \ No newline at end of file diff --git a/rslib/src/storage/deck/update_deck.sql b/rslib/src/storage/deck/update_deck.sql index d9e8a1d8c..7e35c1902 100644 --- a/rslib/src/storage/deck/update_deck.sql +++ b/rslib/src/storage/deck/update_deck.sql @@ -1,4 +1,3 @@ -insert - or replace into decks (id, name, mtime_secs, usn, common, kind) -values - (?, ?, ?, ?, ?, ?) \ No newline at end of file +INSERT + OR REPLACE INTO decks (id, name, mtime_secs, usn, common, kind) +VALUES (?, ?, ?, ?, ?, ?) \ No newline at end of file diff --git a/rslib/src/storage/deckconf/add.sql b/rslib/src/storage/deckconf/add.sql index 280e826db..e21f9e932 100644 --- a/rslib/src/storage/deckconf/add.sql +++ b/rslib/src/storage/deckconf/add.sql @@ -1,19 +1,16 @@ -insert into deck_config (id, name, mtime_secs, usn, config) -values - ( +INSERT INTO deck_config (id, name, mtime_secs, usn, config) +VALUES ( ( - case - when ?1 in ( - select - id - from deck_config - ) then ( - select - max(id) + 1 - from deck_config + CASE + WHEN ?1 IN ( + SELECT id + FROM deck_config + ) THEN ( + SELECT max(id) + 1 + FROM deck_config ) - else ?1 - end + ELSE ?1 + END ), ?, ?, diff --git a/rslib/src/storage/deckconf/add_or_update.sql b/rslib/src/storage/deckconf/add_or_update.sql index b81bcdfb9..d0def6223 100644 --- a/rslib/src/storage/deckconf/add_or_update.sql +++ b/rslib/src/storage/deckconf/add_or_update.sql @@ -1,4 +1,3 @@ -insert - or replace into deck_config (id, name, mtime_secs, usn, config) -values - (?, ?, ?, ?, ?); \ No newline at end of file +INSERT + OR REPLACE INTO deck_config (id, name, mtime_secs, usn, config) +VALUES (?, ?, ?, ?, ?); \ No newline at end of file diff --git a/rslib/src/storage/deckconf/get.sql b/rslib/src/storage/deckconf/get.sql index 18eb27c2c..99ad604c4 100644 --- a/rslib/src/storage/deckconf/get.sql +++ b/rslib/src/storage/deckconf/get.sql @@ -1,7 +1,6 @@ -select - id, +SELECT id, name, mtime_secs, usn, config -from deck_config +FROM deck_config \ No newline at end of file diff --git a/rslib/src/storage/deckconf/update.sql b/rslib/src/storage/deckconf/update.sql index ccebea6f8..b43a430ea 100644 --- a/rslib/src/storage/deckconf/update.sql +++ b/rslib/src/storage/deckconf/update.sql @@ -1,8 +1,6 @@ -update deck_config -set - name = ?, +UPDATE deck_config +SET name = ?, mtime_secs = ?, usn = ?, config = ? -where - id = ?; \ No newline at end of file +WHERE id = ?; \ No newline at end of file diff --git a/rslib/src/storage/graves/add.sql b/rslib/src/storage/graves/add.sql index d01f13c95..05ca02417 100644 --- a/rslib/src/storage/graves/add.sql +++ b/rslib/src/storage/graves/add.sql @@ -1,4 +1,3 @@ -insert - or ignore into graves (usn, oid, type) -values - (?, ?, ?) \ No newline at end of file +INSERT + OR IGNORE INTO graves (usn, oid, type) +VALUES (?, ?, ?) \ No newline at end of file diff --git a/rslib/src/storage/note/add.sql b/rslib/src/storage/note/add.sql index d4b12b6b6..ceac21533 100644 --- a/rslib/src/storage/note/add.sql +++ b/rslib/src/storage/note/add.sql @@ -1,4 +1,4 @@ -insert into notes ( +INSERT INTO notes ( id, guid, mid, @@ -11,21 +11,18 @@ insert into notes ( flags, data ) -values - ( +VALUES ( ( - case - when ?1 in ( - select - id - from notes - ) then ( - select - max(id) + 1 - from notes + CASE + WHEN ?1 IN ( + SELECT id + FROM notes + ) THEN ( + SELECT max(id) + 1 + FROM notes ) - else ?1 - end + ELSE ?1 + END ), ?, ?, diff --git a/rslib/src/storage/note/add_or_update.sql b/rslib/src/storage/note/add_or_update.sql index 08e521f34..dd8008c78 100644 --- a/rslib/src/storage/note/add_or_update.sql +++ b/rslib/src/storage/note/add_or_update.sql @@ -1,5 +1,5 @@ -insert - or replace into notes ( +INSERT + OR REPLACE INTO notes ( id, guid, mid, @@ -12,8 +12,7 @@ insert flags, data ) -values - ( +VALUES ( ?, ?, ?, diff --git a/rslib/src/storage/note/get.sql b/rslib/src/storage/note/get.sql index 76f2905da..fb1ba3619 100644 --- a/rslib/src/storage/note/get.sql +++ b/rslib/src/storage/note/get.sql @@ -1,9 +1,8 @@ -select - id, +SELECT id, guid, mid, mod, usn, tags, flds -from notes \ No newline at end of file +FROM notes \ No newline at end of file diff --git a/rslib/src/storage/note/is_orphaned.sql b/rslib/src/storage/note/is_orphaned.sql index 7b27c1ee9..bd7dfe39f 100644 --- a/rslib/src/storage/note/is_orphaned.sql +++ b/rslib/src/storage/note/is_orphaned.sql @@ -1,5 +1,3 @@ -select - count(id) = 0 -from cards -where - nid = ?; \ No newline at end of file +SELECT COUNT(id) = 0 +FROM cards +WHERE nid = ?; \ No newline at end of file diff --git a/rslib/src/storage/note/update.sql b/rslib/src/storage/note/update.sql index a3d86587a..8adf9dd69 100644 --- a/rslib/src/storage/note/update.sql +++ b/rslib/src/storage/note/update.sql @@ -1,6 +1,5 @@ -update notes -set - guid = ?, +UPDATE notes +SET guid = ?, mid = ?, mod = ?, usn = ?, @@ -8,5 +7,4 @@ set flds = ?, sfld = ?, csum = ? -where - id = ? \ No newline at end of file +WHERE id = ? \ No newline at end of file diff --git a/rslib/src/storage/notetype/add_notetype.sql b/rslib/src/storage/notetype/add_notetype.sql index 4578ab3b4..9cb83ae21 100644 --- a/rslib/src/storage/notetype/add_notetype.sql +++ b/rslib/src/storage/notetype/add_notetype.sql @@ -1,19 +1,16 @@ -insert into notetypes (id, name, mtime_secs, usn, config) -values - ( +INSERT INTO notetypes (id, name, mtime_secs, usn, config) +VALUES ( ( - case - when ?1 in ( - select - id - from notetypes - ) then ( - select - max(id) + 1 - from notetypes + CASE + WHEN ?1 IN ( + SELECT id + FROM notetypes + ) THEN ( + SELECT max(id) + 1 + FROM notetypes ) - else ?1 - end + ELSE ?1 + END ), ?, ?, diff --git a/rslib/src/storage/notetype/add_or_update.sql b/rslib/src/storage/notetype/add_or_update.sql index ec05af6d8..d8054f7bd 100644 --- a/rslib/src/storage/notetype/add_or_update.sql +++ b/rslib/src/storage/notetype/add_or_update.sql @@ -1,4 +1,3 @@ -insert - or replace into notetypes (id, name, mtime_secs, usn, config) -values - (?, ?, ?, ?, ?); \ No newline at end of file +INSERT + OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config) +VALUES (?, ?, ?, ?, ?); \ No newline at end of file diff --git a/rslib/src/storage/notetype/delete_cards_for_template.sql b/rslib/src/storage/notetype/delete_cards_for_template.sql index 38748ebf5..97c5ca0b1 100644 --- a/rslib/src/storage/notetype/delete_cards_for_template.sql +++ b/rslib/src/storage/notetype/delete_cards_for_template.sql @@ -1,10 +1,7 @@ -delete from cards -where - nid in ( - select - id - from notes - where - mid = ? +DELETE FROM cards +WHERE nid IN ( + SELECT id + FROM notes + WHERE mid = ? ) - and ord = ?; \ No newline at end of file + AND ord = ?; \ No newline at end of file diff --git a/rslib/src/storage/notetype/existing_cards.sql b/rslib/src/storage/notetype/existing_cards.sql index 5f4658e05..82bc71836 100644 --- a/rslib/src/storage/notetype/existing_cards.sql +++ b/rslib/src/storage/notetype/existing_cards.sql @@ -1,27 +1,26 @@ -select - id, +SELECT id, nid, ord, -- original deck ( - case + CASE odid - when 0 then did - else odid - end + WHEN 0 THEN did + ELSE odid + END ), -- new position if card is empty ( - case + CASE type - when 0 then ( - case + WHEN 0 THEN ( + CASE odue - when 0 then max(0, due) - else max(odue, 0) - end + WHEN 0 THEN max(0, due) + ELSE max(odue, 0) + END ) - else null - end + ELSE NULL + END ) -from cards c \ No newline at end of file +FROM cards c \ No newline at end of file diff --git a/rslib/src/storage/notetype/field_names_for_notes.sql b/rslib/src/storage/notetype/field_names_for_notes.sql index a805044e3..3aa20c787 100644 --- a/rslib/src/storage/notetype/field_names_for_notes.sql +++ b/rslib/src/storage/notetype/field_names_for_notes.sql @@ -1,10 +1,6 @@ -select - distinct name -from fields -where - ntid in ( - select - mid - from notes - where - id in \ No newline at end of file +SELECT DISTINCT name +FROM FIELDS +WHERE ntid IN ( + SELECT mid + FROM notes + WHERE id IN \ No newline at end of file diff --git a/rslib/src/storage/notetype/get_fields.sql b/rslib/src/storage/notetype/get_fields.sql index aef718770..0213207bf 100644 --- a/rslib/src/storage/notetype/get_fields.sql +++ b/rslib/src/storage/notetype/get_fields.sql @@ -1,9 +1,6 @@ -select - ord, +SELECT ord, name, config -from fields -where - ntid = ? -order by - ord \ No newline at end of file +FROM FIELDS +WHERE ntid = ? +ORDER BY ord \ No newline at end of file diff --git a/rslib/src/storage/notetype/get_notetype.sql b/rslib/src/storage/notetype/get_notetype.sql index f405ed76d..91ed61f59 100644 --- a/rslib/src/storage/notetype/get_notetype.sql +++ b/rslib/src/storage/notetype/get_notetype.sql @@ -1,7 +1,6 @@ -select - id, +SELECT id, name, mtime_secs, usn, config -from notetypes +FROM notetypes \ No newline at end of file diff --git a/rslib/src/storage/notetype/get_notetype_names.sql b/rslib/src/storage/notetype/get_notetype_names.sql index a4393765b..ebbbb61e2 100644 --- a/rslib/src/storage/notetype/get_notetype_names.sql +++ b/rslib/src/storage/notetype/get_notetype_names.sql @@ -1,4 +1,3 @@ -select - id, +SELECT id, name -from notetypes \ No newline at end of file +FROM notetypes \ No newline at end of file diff --git a/rslib/src/storage/notetype/get_templates.sql b/rslib/src/storage/notetype/get_templates.sql index a6fcadb10..dc42818f4 100644 --- a/rslib/src/storage/notetype/get_templates.sql +++ b/rslib/src/storage/notetype/get_templates.sql @@ -1,11 +1,8 @@ -select - ord, +SELECT ord, name, mtime_secs, usn, config -from templates -where - ntid = ? -order by - ord \ No newline at end of file +FROM templates +WHERE ntid = ? +ORDER BY ord \ No newline at end of file diff --git a/rslib/src/storage/notetype/get_use_counts.sql b/rslib/src/storage/notetype/get_use_counts.sql index 7a00bb99f..dc28ce1c9 100644 --- a/rslib/src/storage/notetype/get_use_counts.sql +++ b/rslib/src/storage/notetype/get_use_counts.sql @@ -1,13 +1,9 @@ -select - nt.id, +SELECT nt.id, nt.name, ( - select - count(*) - from notes n - where - nt.id = n.mid + SELECT COUNT(*) + FROM notes n + WHERE nt.id = n.mid ) -from notetypes nt -order by - nt.name \ No newline at end of file +FROM notetypes nt +ORDER BY nt.name \ No newline at end of file diff --git a/rslib/src/storage/notetype/highest_card_ord.sql b/rslib/src/storage/notetype/highest_card_ord.sql index 68c8dc22a..5cefaf39f 100644 --- a/rslib/src/storage/notetype/highest_card_ord.sql +++ b/rslib/src/storage/notetype/highest_card_ord.sql @@ -1,7 +1,7 @@ -select coalesce(max(ord), 0) -from cards -where nid in ( - select id - from notes - where mid = ? - ) \ No newline at end of file +SELECT coalesce(max(ord), 0) +FROM cards +WHERE nid IN ( + SELECT id + FROM notes + WHERE mid = ? + ) \ No newline at end of file diff --git a/rslib/src/storage/notetype/update_fields.sql b/rslib/src/storage/notetype/update_fields.sql index c007f25e4..86eeb85b0 100644 --- a/rslib/src/storage/notetype/update_fields.sql +++ b/rslib/src/storage/notetype/update_fields.sql @@ -1,3 +1,2 @@ -insert into fields (ntid, ord, name, config) -values - (?, ?, ?, ?); \ No newline at end of file +INSERT INTO FIELDS (ntid, ord, name, config) +VALUES (?, ?, ?, ?); \ No newline at end of file diff --git a/rslib/src/storage/notetype/update_notetype_config.sql b/rslib/src/storage/notetype/update_notetype_config.sql index 2ddabad63..19a034222 100644 --- a/rslib/src/storage/notetype/update_notetype_config.sql +++ b/rslib/src/storage/notetype/update_notetype_config.sql @@ -1,4 +1,3 @@ -insert - or replace into notetype_config (ntid, config) -values - (?, ?) \ No newline at end of file +INSERT + OR REPLACE INTO notetype_config (ntid, config) +VALUES (?, ?) \ No newline at end of file diff --git a/rslib/src/storage/notetype/update_notetype_core.sql b/rslib/src/storage/notetype/update_notetype_core.sql index ceb55c55f..84e5f49e9 100644 --- a/rslib/src/storage/notetype/update_notetype_core.sql +++ b/rslib/src/storage/notetype/update_notetype_core.sql @@ -1,4 +1,3 @@ -insert - or replace into notetypes (id, name, mtime_secs, usn, config) -values - (?, ?, ?, ?, ?) \ No newline at end of file +INSERT + OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config) +VALUES (?, ?, ?, ?, ?) \ No newline at end of file diff --git a/rslib/src/storage/notetype/update_templates.sql b/rslib/src/storage/notetype/update_templates.sql index 08d3022fc..b60f2e577 100644 --- a/rslib/src/storage/notetype/update_templates.sql +++ b/rslib/src/storage/notetype/update_templates.sql @@ -1,3 +1,2 @@ -insert into templates (ntid, ord, name, mtime_secs, usn, config) -values - (?, ?, ?, ?, ?, ?) \ No newline at end of file +INSERT INTO templates (ntid, ord, name, mtime_secs, usn, config) +VALUES (?, ?, ?, ?, ?, ?) \ No newline at end of file diff --git a/rslib/src/storage/revlog/add.sql b/rslib/src/storage/revlog/add.sql index b63301200..13f12e073 100644 --- a/rslib/src/storage/revlog/add.sql +++ b/rslib/src/storage/revlog/add.sql @@ -1,5 +1,5 @@ -insert - or ignore into revlog ( +INSERT + OR IGNORE INTO revlog ( id, cid, usn, @@ -10,18 +10,18 @@ insert time, type ) -values ( +VALUES ( ( - case - when ?1 in ( - select id - from revlog - ) then ( - select max(id) + 1 - from revlog + CASE + WHEN ?1 IN ( + SELECT id + FROM revlog + ) THEN ( + SELECT max(id) + 1 + FROM revlog ) - else ?1 - end + ELSE ?1 + END ), ?, ?, diff --git a/rslib/src/storage/revlog/fix_props.sql b/rslib/src/storage/revlog/fix_props.sql index 1a4ceebd0..28bffb431 100644 --- a/rslib/src/storage/revlog/fix_props.sql +++ b/rslib/src/storage/revlog/fix_props.sql @@ -1,7 +1,7 @@ -update revlog -set ivl = min(max(round(ivl), -2147483648), 2147483647), +UPDATE revlog +SET ivl = min(max(round(ivl), -2147483648), 2147483647), lastIvl = min(max(round(lastIvl), -2147483648), 2147483647), time = min(max(round(time), 0), 2147483647) -where ivl != min(max(round(ivl), -2147483648), 2147483647) - or lastIvl != min(max(round(lastIvl), -2147483648), 2147483647) - or time != min(max(round(time), 0), 2147483647) \ No newline at end of file +WHERE ivl != min(max(round(ivl), -2147483648), 2147483647) + OR lastIvl != min(max(round(lastIvl), -2147483648), 2147483647) + OR time != min(max(round(time), 0), 2147483647) \ No newline at end of file diff --git a/rslib/src/storage/revlog/get.sql b/rslib/src/storage/revlog/get.sql index 671eb1846..647ea5f55 100644 --- a/rslib/src/storage/revlog/get.sql +++ b/rslib/src/storage/revlog/get.sql @@ -1,5 +1,4 @@ -select - id, +SELECT id, cid, usn, ease, @@ -8,4 +7,4 @@ select factor, time, type -from revlog \ No newline at end of file +FROM revlog \ No newline at end of file diff --git a/rslib/src/storage/revlog/studied_today.sql b/rslib/src/storage/revlog/studied_today.sql index 73f8cfba3..2a341f632 100644 --- a/rslib/src/storage/revlog/studied_today.sql +++ b/rslib/src/storage/revlog/studied_today.sql @@ -1,5 +1,5 @@ -select count(), - coalesce(sum(time) / 1000.0, 0.0) -from revlog -where id > ? - and type != ? \ No newline at end of file +SELECT COUNT(), + coalesce(sum(time) / 1000.0, 0.0) +FROM revlog +WHERE id > ? + AND type != ? \ No newline at end of file diff --git a/rslib/src/storage/schema11.sql b/rslib/src/storage/schema11.sql index e5d1b7f4d..633a796d2 100644 --- a/rslib/src/storage/schema11.sql +++ b/rslib/src/storage/schema11.sql @@ -1,88 +1,92 @@ -create table col -( - id integer primary key, - crt integer not null, - mod integer not null, - scm integer not null, - ver integer not null, - dty integer not null, - usn integer not null, - ls integer not null, - conf text not null, - models text not null, - decks text not null, - dconf text not null, - tags text not null +CREATE TABLE col ( + id integer PRIMARY KEY, + crt integer NOT NULL, + mod integer NOT NULL, + scm integer NOT NULL, + ver integer NOT NULL, + dty integer NOT NULL, + usn integer NOT NULL, + ls integer NOT NULL, + conf text NOT NULL, + models text NOT NULL, + decks text NOT NULL, + dconf text NOT NULL, + tags text NOT NULL ); - -create table notes -( - id integer primary key, - guid text not null, - mid integer not null, - mod integer not null, - usn integer not null, - tags text not null, - flds text not null, - sfld integer not null, - csum integer not null, - flags integer not null, - data text not null +CREATE TABLE notes ( + id integer PRIMARY KEY, + guid text NOT NULL, + mid integer NOT NULL, + mod integer NOT NULL, + usn integer NOT NULL, + tags text NOT NULL, + flds text NOT NULL, + sfld integer NOT NULL, + csum integer NOT NULL, + flags integer NOT NULL, + data text NOT NULL ); - -create table cards -( - id integer primary key, - nid integer not null, - did integer not null, - ord integer not null, - mod integer not null, - usn integer not null, - type integer not null, - queue integer not null, - due integer not null, - ivl integer not null, - factor integer not null, - reps integer not null, - lapses integer not null, - left integer not null, - odue integer not null, - odid integer not null, - flags integer not null, - data text not null +CREATE TABLE cards ( + id integer PRIMARY KEY, + nid integer NOT NULL, + did integer NOT NULL, + ord integer NOT NULL, + mod integer NOT NULL, + usn integer NOT NULL, + type integer NOT NULL, + queue integer NOT NULL, + due integer NOT NULL, + ivl integer NOT NULL, + factor integer NOT NULL, + reps integer NOT NULL, + lapses integer NOT NULL, + left integer NOT NULL, + odue integer NOT NULL, + odid integer NOT NULL, + flags integer NOT NULL, + data text NOT NULL ); - -create table revlog -( - id integer primary key, - cid integer not null, - usn integer not null, - ease integer not null, - ivl integer not null, - lastIvl integer not null, - factor integer not null, - time integer not null, - type integer not null +CREATE TABLE revlog ( + id integer PRIMARY KEY, + cid integer NOT NULL, + usn integer NOT NULL, + ease integer NOT NULL, + ivl integer NOT NULL, + lastIvl integer NOT NULL, + factor integer NOT NULL, + time integer NOT NULL, + type integer NOT NULL ); - -create table graves -( - usn integer not null, - oid integer not null, - type integer not null +CREATE TABLE graves ( + usn integer NOT NULL, + oid integer NOT NULL, + type integer NOT NULL ); - -- syncing -create index ix_notes_usn on notes (usn); -create index ix_cards_usn on cards (usn); -create index ix_revlog_usn on revlog (usn); +CREATE INDEX ix_notes_usn ON notes (usn); +CREATE INDEX ix_cards_usn ON cards (usn); +CREATE INDEX ix_revlog_usn ON revlog (usn); -- card spacing, etc -create index ix_cards_nid on cards (nid); +CREATE INDEX ix_cards_nid ON cards (nid); -- scheduling and deck limiting -create index ix_cards_sched on cards (did, queue, due); +CREATE INDEX ix_cards_sched ON cards (did, queue, due); -- revlog by card -create index ix_revlog_cid on revlog (cid); +CREATE INDEX ix_revlog_cid ON revlog (cid); -- field uniqueness -create index ix_notes_csum on notes (csum); - -insert into col values (1,0,0,0,0,0,0,0,'{}','{}','{}','{}','{}'); +CREATE INDEX ix_notes_csum ON notes (csum); +INSERT INTO col +VALUES ( + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + '{}', + '{}', + '{}', + '{}', + '{}' + ); \ No newline at end of file diff --git a/rslib/src/storage/tag/add.sql b/rslib/src/storage/tag/add.sql index 8fee01a4c..211807a5f 100644 --- a/rslib/src/storage/tag/add.sql +++ b/rslib/src/storage/tag/add.sql @@ -1,4 +1,3 @@ -insert - or ignore into tags (tag, usn) -values - (?, ?) \ No newline at end of file +INSERT + OR IGNORE INTO tags (tag, usn) +VALUES (?, ?) \ No newline at end of file diff --git a/rslib/src/storage/upgrades/schema11_downgrade.sql b/rslib/src/storage/upgrades/schema11_downgrade.sql index ed7694ad7..03b73c5d5 100644 --- a/rslib/src/storage/upgrades/schema11_downgrade.sql +++ b/rslib/src/storage/upgrades/schema11_downgrade.sql @@ -1,12 +1,11 @@ -drop table config; -drop table deck_config; -drop table tags; -drop table fields; -drop table templates; -drop table notetypes; -drop table decks; -drop index idx_cards_odid; -drop index idx_notes_mid; -update col -set - ver = 11; \ No newline at end of file +DROP TABLE config; +DROP TABLE deck_config; +DROP TABLE tags; +DROP TABLE FIELDS; +DROP TABLE templates; +DROP TABLE notetypes; +DROP TABLE decks; +DROP INDEX idx_cards_odid; +DROP INDEX idx_notes_mid; +UPDATE col +SET ver = 11; \ No newline at end of file diff --git a/rslib/src/storage/upgrades/schema14_upgrade.sql b/rslib/src/storage/upgrades/schema14_upgrade.sql index ccd9352a4..cd602ce17 100644 --- a/rslib/src/storage/upgrades/schema14_upgrade.sql +++ b/rslib/src/storage/upgrades/schema14_upgrade.sql @@ -1,20 +1,19 @@ -create table deck_config ( - id integer primary key not null, - name text not null collate unicase, - mtime_secs integer not null, - usn integer not null, - config blob not null +CREATE TABLE deck_config ( + id integer PRIMARY KEY NOT NULL, + name text NOT NULL COLLATE unicase, + mtime_secs integer NOT NULL, + usn integer NOT NULL, + config blob NOT NULL ); -create table config ( - key text not null primary key, - usn integer not null, - mtime_secs integer not null, - val blob not null +CREATE TABLE config ( + KEY text NOT NULL PRIMARY KEY, + usn integer NOT NULL, + mtime_secs integer NOT NULL, + val blob NOT NULL ) without rowid; -create table tags ( - tag text not null primary key collate unicase, - usn integer not null +CREATE TABLE tags ( + tag text NOT NULL PRIMARY KEY COLLATE unicase, + usn integer NOT NULL ) without rowid; -update col -set - ver = 14; \ No newline at end of file +UPDATE col +SET ver = 14; \ No newline at end of file diff --git a/rslib/src/storage/upgrades/schema15_upgrade.sql b/rslib/src/storage/upgrades/schema15_upgrade.sql index 5af87298c..4fa23c8c6 100644 --- a/rslib/src/storage/upgrades/schema15_upgrade.sql +++ b/rslib/src/storage/upgrades/schema15_upgrade.sql @@ -1,45 +1,43 @@ -create table fields ( - ntid integer not null, - ord integer not null, - name text not null collate unicase, - config blob not null, - primary key (ntid, ord) +CREATE TABLE FIELDS ( + ntid integer NOT NULL, + ord integer NOT NULL, + name text NOT NULL COLLATE unicase, + config blob NOT NULL, + PRIMARY KEY (ntid, ord) ) without rowid; -create unique index idx_fields_name_ntid on fields (name, ntid); -create table templates ( - ntid integer not null, - ord integer not null, - name text not null collate unicase, - mtime_secs integer not null, - usn integer not null, - config blob not null, - primary key (ntid, ord) +CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid); +CREATE TABLE templates ( + ntid integer NOT NULL, + ord integer NOT NULL, + name text NOT NULL COLLATE unicase, + mtime_secs integer NOT NULL, + usn integer NOT NULL, + config blob NOT NULL, + PRIMARY KEY (ntid, ord) ) without rowid; -create unique index idx_templates_name_ntid on templates (name, ntid); -create index idx_templates_usn on templates (usn); -create table notetypes ( - id integer not null primary key, - name text not null collate unicase, - mtime_secs integer not null, - usn integer not null, - config blob not null +CREATE UNIQUE INDEX idx_templates_name_ntid ON templates (name, ntid); +CREATE INDEX idx_templates_usn ON templates (usn); +CREATE TABLE notetypes ( + id integer NOT NULL PRIMARY KEY, + name text NOT NULL COLLATE unicase, + mtime_secs integer NOT NULL, + usn integer NOT NULL, + config blob NOT NULL ); -create unique index idx_notetypes_name on notetypes (name); -create index idx_notetypes_usn on notetypes (usn); -create table decks ( - id integer primary key not null, - name text not null collate unicase, - mtime_secs integer not null, - usn integer not null, - common blob not null, - kind blob not null +CREATE UNIQUE INDEX idx_notetypes_name ON notetypes (name); +CREATE INDEX idx_notetypes_usn ON notetypes (usn); +CREATE TABLE decks ( + id integer PRIMARY KEY NOT NULL, + name text NOT NULL COLLATE unicase, + mtime_secs integer NOT NULL, + usn integer NOT NULL, + common blob NOT NULL, + kind blob NOT NULL ); -create unique index idx_decks_name on decks (name); -create index idx_notes_mid on notes (mid); -create index idx_cards_odid on cards (odid) -where - odid != 0; -update col -set - ver = 15; -analyze; \ No newline at end of file +CREATE UNIQUE INDEX idx_decks_name ON decks (name); +CREATE INDEX idx_notes_mid ON notes (mid); +CREATE INDEX idx_cards_odid ON cards (odid) +WHERE odid != 0; +UPDATE col +SET ver = 15; +ANALYZE; \ No newline at end of file