mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 09:16:38 -04:00
Merge branch 'master' into backend-filters
Adapt new formatting.
This commit is contained in:
commit
f83553c82a
81 changed files with 1436 additions and 1285 deletions
3
defs.bzl
3
defs.bzl
|
@ -4,6 +4,7 @@ load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
|
||||||
load("@net_ankiweb_anki//cargo:crates.bzl", "raze_fetch_remote_crates")
|
load("@net_ankiweb_anki//cargo:crates.bzl", "raze_fetch_remote_crates")
|
||||||
load(":python.bzl", "setup_local_python")
|
load(":python.bzl", "setup_local_python")
|
||||||
load(":protobuf.bzl", "setup_protobuf_binary")
|
load(":protobuf.bzl", "setup_protobuf_binary")
|
||||||
|
load("//rslib:clang_format.bzl", "setup_clang_format")
|
||||||
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||||
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
|
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
|
||||||
load("@build_bazel_rules_svelte//:defs.bzl", "rules_svelte_dependencies")
|
load("@build_bazel_rules_svelte//:defs.bzl", "rules_svelte_dependencies")
|
||||||
|
@ -28,6 +29,8 @@ def setup_deps():
|
||||||
|
|
||||||
setup_protobuf_binary(name = "com_google_protobuf")
|
setup_protobuf_binary(name = "com_google_protobuf")
|
||||||
|
|
||||||
|
setup_clang_format(name = "clang_format")
|
||||||
|
|
||||||
native.register_toolchains("@python//:python3_toolchain")
|
native.register_toolchains("@python//:python3_toolchain")
|
||||||
|
|
||||||
pip_import(
|
pip_import(
|
||||||
|
|
|
@ -115,6 +115,8 @@ in the relevant package:
|
||||||
|
|
||||||
```
|
```
|
||||||
bazel run //rslib:format
|
bazel run //rslib:format
|
||||||
|
bazel run //rslib:sql_format
|
||||||
|
bazel run //rslib:proto_format
|
||||||
bazel run //pylib:format
|
bazel run //pylib:format
|
||||||
bazel run //qt:format
|
bazel run //qt:format
|
||||||
bazel run //ts:format
|
bazel run //ts:format
|
||||||
|
|
|
@ -136,7 +136,6 @@ class DataModel(QAbstractTableModel):
|
||||||
if role == Qt.FontRole:
|
if role == Qt.FontRole:
|
||||||
if self.activeCols[index.column()] not in ("question", "answer", "noteFld"):
|
if self.activeCols[index.column()] not in ("question", "answer", "noteFld"):
|
||||||
return
|
return
|
||||||
row = index.row()
|
|
||||||
c = self.getCard(index)
|
c = self.getCard(index)
|
||||||
t = c.template()
|
t = c.template()
|
||||||
if not t.get("bfont"):
|
if not t.get("bfont"):
|
||||||
|
@ -298,7 +297,6 @@ class DataModel(QAbstractTableModel):
|
||||||
return "%Y-%m-%d"
|
return "%Y-%m-%d"
|
||||||
|
|
||||||
def columnData(self, index):
|
def columnData(self, index):
|
||||||
row = index.row()
|
|
||||||
col = index.column()
|
col = index.column()
|
||||||
type = self.columnType(col)
|
type = self.columnType(col)
|
||||||
c = self.getCard(index)
|
c = self.getCard(index)
|
||||||
|
@ -393,7 +391,6 @@ class DataModel(QAbstractTableModel):
|
||||||
if type != "noteFld":
|
if type != "noteFld":
|
||||||
return False
|
return False
|
||||||
|
|
||||||
row = index.row()
|
|
||||||
c = self.getCard(index)
|
c = self.getCard(index)
|
||||||
nt = c.note().model()
|
nt = c.note().model()
|
||||||
return nt["flds"][self.col.models.sortIdx(nt)]["rtl"]
|
return nt["flds"][self.col.models.sortIdx(nt)]["rtl"]
|
||||||
|
@ -2073,7 +2070,7 @@ where id in %s"""
|
||||||
self.model.beginReset()
|
self.model.beginReset()
|
||||||
self.mw.checkpoint(tr(TR.BROWSING_TAG_DUPLICATES))
|
self.mw.checkpoint(tr(TR.BROWSING_TAG_DUPLICATES))
|
||||||
nids = set()
|
nids = set()
|
||||||
for s, nidlist in res:
|
for _, nidlist in res:
|
||||||
nids.update(nidlist)
|
nids.update(nidlist)
|
||||||
self.col.tags.bulkAdd(list(nids), tr(TR.BROWSING_DUPLICATE))
|
self.col.tags.bulkAdd(list(nids), tr(TR.BROWSING_DUPLICATE))
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
|
|
|
@ -270,7 +270,6 @@ class AnkiQt(QMainWindow):
|
||||||
# called on .clear()
|
# called on .clear()
|
||||||
return
|
return
|
||||||
name = self.pm.profiles()[n]
|
name = self.pm.profiles()[n]
|
||||||
f = self.profileForm
|
|
||||||
self.pm.load(name)
|
self.pm.load(name)
|
||||||
|
|
||||||
def openProfile(self):
|
def openProfile(self):
|
||||||
|
|
|
@ -71,7 +71,6 @@ class TagLimit(QDialog):
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
self.hide()
|
self.hide()
|
||||||
n = 0
|
|
||||||
# gather yes/no tags
|
# gather yes/no tags
|
||||||
yes = []
|
yes = []
|
||||||
no = []
|
no = []
|
||||||
|
|
|
@ -201,16 +201,11 @@ class ButtonedDialog(QMessageBox):
|
||||||
self.help = help
|
self.help = help
|
||||||
self.setIcon(QMessageBox.Warning)
|
self.setIcon(QMessageBox.Warning)
|
||||||
self.setText(text)
|
self.setText(text)
|
||||||
# v = QVBoxLayout()
|
|
||||||
# v.addWidget(QLabel(text))
|
|
||||||
# box = QDialogButtonBox()
|
|
||||||
# v.addWidget(box)
|
|
||||||
for b in buttons:
|
for b in buttons:
|
||||||
self._buttons.append(self.addButton(b, QMessageBox.AcceptRole))
|
self._buttons.append(self.addButton(b, QMessageBox.AcceptRole))
|
||||||
if help:
|
if help:
|
||||||
self.addButton(tr(TR.ACTIONS_HELP), QMessageBox.HelpRole)
|
self.addButton(tr(TR.ACTIONS_HELP), QMessageBox.HelpRole)
|
||||||
buttons.append(tr(TR.ACTIONS_HELP))
|
buttons.append(tr(TR.ACTIONS_HELP))
|
||||||
# self.setLayout(v)
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
|
@ -22,7 +22,7 @@ if __name__ == "__main__":
|
||||||
"black",
|
"black",
|
||||||
"-t",
|
"-t",
|
||||||
"py38",
|
"py38",
|
||||||
"--exclude=aqt/forms|colors",
|
"--exclude=aqt/forms|colors|_gen",
|
||||||
"aqt",
|
"aqt",
|
||||||
"tests",
|
"tests",
|
||||||
"tools",
|
"tools",
|
||||||
|
|
|
@ -2,6 +2,8 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||||
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
|
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library", "rust_test")
|
||||||
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script")
|
||||||
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
load(":rustfmt.bzl", "rustfmt_fix", "rustfmt_test")
|
||||||
|
load(":clang_format.bzl", "proto_format")
|
||||||
|
load("//ts:sql_format.bzl", "sql_format")
|
||||||
|
|
||||||
# Build script
|
# Build script
|
||||||
#######################
|
#######################
|
||||||
|
@ -143,6 +145,16 @@ rustfmt_fix(
|
||||||
]),
|
]),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sql_format(
|
||||||
|
name = "sql_format",
|
||||||
|
srcs = glob(["**/*.sql"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
proto_format(
|
||||||
|
name = "proto_format",
|
||||||
|
srcs = ["backend.proto"],
|
||||||
|
)
|
||||||
|
|
||||||
# fluent.proto generation
|
# fluent.proto generation
|
||||||
###########################
|
###########################
|
||||||
# This separate step is required to make the file available to downstream consumers.
|
# This separate step is required to make the file available to downstream consumers.
|
||||||
|
|
1339
rslib/backend.proto
1339
rslib/backend.proto
File diff suppressed because it is too large
Load diff
73
rslib/clang_format.bzl
Normal file
73
rslib/clang_format.bzl
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
"""
|
||||||
|
Exposes a clang-format binary for formatting protobuf.
|
||||||
|
"""
|
||||||
|
|
||||||
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||||
|
load("@rules_python//python:defs.bzl", "py_test")
|
||||||
|
|
||||||
|
def _impl(rctx):
|
||||||
|
rctx.file("BUILD.bazel", """
|
||||||
|
alias(
|
||||||
|
name = "clang_format",
|
||||||
|
actual = select({
|
||||||
|
"@net_ankiweb_anki//platforms:windows_x86_64": "@clang_format_windows_x86_64//:clang-format.exe",
|
||||||
|
"@net_ankiweb_anki//platforms:macos_x86_64": "@clang_format_macos_x86_64//:clang-format",
|
||||||
|
"@net_ankiweb_anki//platforms:linux_x86_64": "@clang_format_linux_x86_64//:clang-format",
|
||||||
|
}),
|
||||||
|
visibility = ["//visibility:public"]
|
||||||
|
)
|
||||||
|
""")
|
||||||
|
|
||||||
|
_setup_clang_format = repository_rule(
|
||||||
|
attrs = {},
|
||||||
|
local = True,
|
||||||
|
implementation = _impl,
|
||||||
|
)
|
||||||
|
|
||||||
|
def setup_clang_format(name):
|
||||||
|
maybe(
|
||||||
|
http_archive,
|
||||||
|
name = "clang_format_macos_x86_64",
|
||||||
|
build_file_content = """exports_files(["clang-format"])""",
|
||||||
|
sha256 = "238be68d9478163a945754f06a213483473044f5a004c4125d3d9d8d3556466e",
|
||||||
|
urls = [
|
||||||
|
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_macos_x86_64.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
maybe(
|
||||||
|
http_archive,
|
||||||
|
name = "clang_format_linux_x86_64",
|
||||||
|
build_file_content = """exports_files(["clang-format"])""",
|
||||||
|
sha256 = "64060bc4dbca30d0d96aab9344e2783008b16e1cae019a2532f1126ca5ec5449",
|
||||||
|
urls = [
|
||||||
|
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_linux_x86_64.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
maybe(
|
||||||
|
http_archive,
|
||||||
|
name = "clang_format_windows_x86_64",
|
||||||
|
build_file_content = """exports_files(["clang-format.exe"])""",
|
||||||
|
sha256 = "7d9f6915e3f0fb72407830f0fc37141308d2e6915daba72987a52f309fbeaccc",
|
||||||
|
urls = [
|
||||||
|
"https://github.com/ankitects/clang-format-binaries/releases/download/anki-2021-01-09/clang-format_windows_x86_64.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
if not native.existing_rule(name):
|
||||||
|
_setup_clang_format(
|
||||||
|
name = name,
|
||||||
|
)
|
||||||
|
|
||||||
|
def proto_format(name, srcs, **kwargs):
|
||||||
|
py_test(
|
||||||
|
name = name,
|
||||||
|
srcs = [
|
||||||
|
"proto_format.py",
|
||||||
|
],
|
||||||
|
data = ["@clang_format//:clang_format"] + srcs,
|
||||||
|
args = ["$(location @clang_format//:clang_format)"] + [native.package_name() + "/" + f for f in srcs],
|
||||||
|
**kwargs
|
||||||
|
)
|
36
rslib/proto_format.py
Executable file
36
rslib/proto_format.py
Executable file
|
@ -0,0 +1,36 @@
|
||||||
|
import sys, subprocess, os, difflib
|
||||||
|
|
||||||
|
clang_format = sys.argv[1]
|
||||||
|
workspace = os.environ.get("BUILD_WORKSPACE_DIRECTORY", "")
|
||||||
|
want_fix = bool(workspace)
|
||||||
|
|
||||||
|
found_bad = False
|
||||||
|
for path in sys.argv[2:]:
|
||||||
|
with open(path) as file:
|
||||||
|
orig = file.read()
|
||||||
|
new = subprocess.check_output(
|
||||||
|
# [clang_format, "--style={'BasedOnStyle': 'google', 'IndentWidth': 4}", path]
|
||||||
|
[clang_format, "--style=google", path]
|
||||||
|
).decode("utf-8")
|
||||||
|
if orig != new:
|
||||||
|
if want_fix:
|
||||||
|
with open(os.path.join(workspace, path), "w") as file:
|
||||||
|
file.write(new)
|
||||||
|
print("fixed", path)
|
||||||
|
else:
|
||||||
|
print(f"Bad formatting in {path}")
|
||||||
|
print(
|
||||||
|
"\n".join(
|
||||||
|
difflib.unified_diff(
|
||||||
|
orig.splitlines(),
|
||||||
|
new.splitlines(),
|
||||||
|
fromfile="bad",
|
||||||
|
tofile="good",
|
||||||
|
lineterm="",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
found_bad = True
|
||||||
|
|
||||||
|
if found_bad:
|
||||||
|
sys.exit(1)
|
|
@ -1,10 +1,13 @@
|
||||||
create table media (
|
CREATE TABLE media (
|
||||||
fname text not null primary key,
|
fname text NOT NULL PRIMARY KEY,
|
||||||
csum text, -- null indicates deleted file
|
-- null indicates deleted file
|
||||||
mtime int not null, -- zero if deleted
|
csum text,
|
||||||
dirty int not null
|
-- zero if deleted
|
||||||
|
mtime int NOT NULL,
|
||||||
|
dirty int NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
|
CREATE INDEX idx_media_dirty ON media (dirty)
|
||||||
create index idx_media_dirty on media (dirty) where dirty=1;
|
WHERE dirty = 1;
|
||||||
|
CREATE TABLE meta (dirMod int, lastUsn int);
|
||||||
create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
INSERT INTO meta
|
||||||
|
VALUES (0, 0);
|
|
@ -4,7 +4,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
card::{Card, CardID, CardQueue, CardType},
|
card::{Card, CardID, CardQueue, CardType},
|
||||||
collection::Collection,
|
collection::Collection,
|
||||||
deckconf::INITIAL_EASE_FACTOR_THOUSANDS,
|
|
||||||
decks::DeckID,
|
decks::DeckID,
|
||||||
err::Result,
|
err::Result,
|
||||||
notes::NoteID,
|
notes::NoteID,
|
||||||
|
@ -21,11 +20,7 @@ impl Card {
|
||||||
self.ctype = CardType::New;
|
self.ctype = CardType::New;
|
||||||
self.queue = CardQueue::New;
|
self.queue = CardQueue::New;
|
||||||
self.interval = 0;
|
self.interval = 0;
|
||||||
if self.ease_factor == 0 {
|
self.ease_factor = 0;
|
||||||
// unlike the old Python code, we leave the ease factor alone
|
|
||||||
// if it's already set
|
|
||||||
self.ease_factor = INITIAL_EASE_FACTOR_THOUSANDS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// If the card is new, change its position.
|
/// If the card is new, change its position.
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
did integer not null unique
|
did integer NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
insert into sort_order (did)
|
INSERT INTO sort_order (did)
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM decks
|
||||||
from decks
|
ORDER BY name;
|
||||||
order by
|
|
||||||
name;
|
|
|
@ -1,11 +1,9 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
ntid integer not null unique
|
ntid integer NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
insert into sort_order (ntid)
|
INSERT INTO sort_order (ntid)
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notetypes
|
||||||
from notetypes
|
ORDER BY name;
|
||||||
order by
|
|
||||||
name;
|
|
|
@ -1,14 +1,12 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
unique(ntid, ord)
|
UNIQUE(ntid, ord)
|
||||||
);
|
);
|
||||||
insert into sort_order (ntid, ord)
|
INSERT INTO sort_order (ntid, ord)
|
||||||
select
|
SELECT ntid,
|
||||||
ntid,
|
|
||||||
ord
|
ord
|
||||||
from templates
|
FROM templates
|
||||||
order by
|
ORDER BY name
|
||||||
name
|
|
|
@ -1,4 +1,4 @@
|
||||||
insert into cards (
|
INSERT INTO cards (
|
||||||
id,
|
id,
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
|
@ -18,21 +18,18 @@ insert into cards (
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM cards
|
||||||
from cards
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM cards
|
||||||
max(id) + 1
|
|
||||||
from cards
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into cards (
|
OR REPLACE INTO cards (
|
||||||
id,
|
id,
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
|
@ -19,8 +19,7 @@ insert
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert into search_cids
|
INSERT INTO search_cids
|
||||||
select id
|
SELECT id
|
||||||
from cards
|
FROM cards
|
||||||
where due >= ?
|
WHERE due >= ?
|
||||||
and type = ?
|
AND type = ?
|
|
@ -1,28 +1,28 @@
|
||||||
select coalesce(
|
SELECT coalesce(
|
||||||
sum(
|
sum(
|
||||||
queue in (:review_queue, :day_learn_queue)
|
queue IN (:review_queue, :day_learn_queue)
|
||||||
and due <= :today
|
AND due <= :today
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
) as review_count,
|
) AS review_count,
|
||||||
coalesce(sum(queue = :new_queue), 0) as new_count,
|
coalesce(sum(queue = :new_queue), 0) AS new_count,
|
||||||
coalesce(sum(queue = :sched_buried_queue), 0) as sched_buried,
|
coalesce(sum(queue = :sched_buried_queue), 0) AS sched_buried,
|
||||||
coalesce(sum(queue = :user_buried_queue), 0) as user_buried,
|
coalesce(sum(queue = :user_buried_queue), 0) AS user_buried,
|
||||||
coalesce(sum(queue = :learn_queue), 0) as learn_count,
|
coalesce(sum(queue = :learn_queue), 0) AS learn_count,
|
||||||
max(
|
max(
|
||||||
0,
|
0,
|
||||||
coalesce(
|
coalesce(
|
||||||
min(
|
min(
|
||||||
case
|
CASE
|
||||||
when queue = :learn_queue then due
|
WHEN queue = :learn_queue THEN due
|
||||||
else null
|
ELSE NULL
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
)
|
|
||||||
) as first_learn_due
|
|
||||||
from cards
|
|
||||||
where did in (
|
|
||||||
select id
|
|
||||||
from active_decks
|
|
||||||
)
|
)
|
||||||
|
) AS first_learn_due
|
||||||
|
FROM cards
|
||||||
|
WHERE did IN (
|
||||||
|
SELECT id
|
||||||
|
FROM active_decks
|
||||||
|
)
|
|
@ -1,20 +1,18 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET due = (
|
||||||
due = (
|
CASE
|
||||||
case
|
WHEN type = 0
|
||||||
when type = 0
|
AND queue != 4 THEN 1000000 + due % 1000000
|
||||||
and queue != 4 then 1000000 + due % 1000000
|
ELSE due
|
||||||
else due
|
END
|
||||||
end
|
|
||||||
),
|
),
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE due != (
|
||||||
due != (
|
CASE
|
||||||
case
|
WHEN type = 0
|
||||||
when type = 0
|
AND queue != 4 THEN 1000000 + due % 1000000
|
||||||
and queue != 4 then 1000000 + due % 1000000
|
ELSE due
|
||||||
else due
|
END
|
||||||
end
|
|
||||||
)
|
)
|
||||||
and due >= 1000000;
|
AND due >= 1000000;
|
|
@ -1,19 +1,17 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET due = (
|
||||||
due = (
|
CASE
|
||||||
case
|
WHEN queue = 2
|
||||||
when queue = 2
|
AND due > 100000 THEN ?1
|
||||||
and due > 100000 then ?1
|
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||||
else min(max(round(due), -2147483648), 2147483647)
|
END
|
||||||
end
|
|
||||||
),
|
),
|
||||||
mod = ?2,
|
mod = ?2,
|
||||||
usn = ?3
|
usn = ?3
|
||||||
where
|
WHERE due != (
|
||||||
due != (
|
CASE
|
||||||
case
|
WHEN queue = 2
|
||||||
when queue = 2
|
AND due > 100000 THEN ?1
|
||||||
and due > 100000 then ?1
|
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||||
else min(max(round(due), -2147483648), 2147483647)
|
END
|
||||||
end
|
|
||||||
);
|
);
|
|
@ -1,7 +1,5 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET ivl = min(max(round(ivl), 0), 2147483647),
|
||||||
ivl = min(max(round(ivl), 0), 2147483647),
|
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE ivl != min(max(round(ivl), 0), 2147483647)
|
||||||
ivl != min(max(round(ivl), 0), 2147483647)
|
|
|
@ -1,10 +1,10 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set factor = 2500,
|
SET factor = 2500,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
mod = ?
|
mod = ?
|
||||||
where factor != 0
|
WHERE factor != 0
|
||||||
and factor <= 2000
|
AND factor <= 2000
|
||||||
and (
|
AND (
|
||||||
did in DECK_IDS
|
did IN DECK_IDS
|
||||||
or odid in DECK_IDS
|
OR odid IN DECK_IDS
|
||||||
)
|
)
|
|
@ -1,27 +1,25 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET odue = (
|
||||||
odue = (
|
CASE
|
||||||
case
|
WHEN odue > 0
|
||||||
when odue > 0
|
AND (
|
||||||
and (
|
|
||||||
type = 1
|
type = 1
|
||||||
or queue = 2
|
OR queue = 2
|
||||||
)
|
)
|
||||||
and not odid then 0
|
AND NOT odid THEN 0
|
||||||
else min(max(round(odue), -2147483648), 2147483647)
|
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE odue != (
|
||||||
odue != (
|
CASE
|
||||||
case
|
WHEN odue > 0
|
||||||
when odue > 0
|
AND (
|
||||||
and (
|
|
||||||
type = 1
|
type = 1
|
||||||
or queue = 2
|
OR queue = 2
|
||||||
)
|
)
|
||||||
and not odid then 0
|
AND NOT odid THEN 0
|
||||||
else min(max(round(odue), -2147483648), 2147483647)
|
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||||
end
|
END
|
||||||
);
|
);
|
|
@ -1,14 +1,13 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
ord,
|
ord,
|
||||||
cast(mod as integer),
|
cast(mod AS integer),
|
||||||
usn,
|
usn,
|
||||||
type,
|
type,
|
||||||
queue,
|
queue,
|
||||||
due,
|
due,
|
||||||
cast(ivl as integer),
|
cast(ivl AS integer),
|
||||||
factor,
|
factor,
|
||||||
reps,
|
reps,
|
||||||
lapses,
|
lapses,
|
||||||
|
@ -17,4 +16,4 @@ select
|
||||||
odid,
|
odid,
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
from cards
|
FROM cards
|
|
@ -1,2 +1,2 @@
|
||||||
drop table if exists search_cids;
|
DROP TABLE IF EXISTS search_cids;
|
||||||
create temporary table search_cids (cid integer primary key not null);
|
CREATE TEMPORARY TABLE search_cids (cid integer PRIMARY KEY NOT NULL);
|
|
@ -1,2 +1,2 @@
|
||||||
drop table if exists search_cids;
|
DROP TABLE IF EXISTS search_cids;
|
||||||
create temporary table search_cids (cid integer not null);
|
CREATE TEMPORARY TABLE search_cids (cid integer NOT NULL);
|
|
@ -1,6 +1,5 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET nid = ?,
|
||||||
nid = ?,
|
|
||||||
did = ?,
|
did = ?,
|
||||||
ord = ?,
|
ord = ?,
|
||||||
mod = ?,
|
mod = ?,
|
||||||
|
@ -17,5 +16,4 @@ set
|
||||||
odid = ?,
|
odid = ?,
|
||||||
flags = ?,
|
flags = ?,
|
||||||
data = ?
|
data = ?
|
||||||
where
|
WHERE id = ?
|
||||||
id = ?
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into config (key, usn, mtime_secs, val)
|
OR REPLACE INTO config (KEY, usn, mtime_secs, val)
|
||||||
values
|
VALUES (?, ?, ?, ?)
|
||||||
(?, ?, ?, ?)
|
|
|
@ -1,5 +1,3 @@
|
||||||
select
|
SELECT val
|
||||||
val
|
FROM config
|
||||||
from config
|
WHERE KEY = ?
|
||||||
where
|
|
||||||
key = ?
|
|
|
@ -1,13 +1,10 @@
|
||||||
select
|
SELECT CASE
|
||||||
case
|
WHEN ?1 IN (
|
||||||
when ?1 in (
|
SELECT id
|
||||||
select
|
FROM decks
|
||||||
id
|
) THEN (
|
||||||
from decks
|
SELECT max(id) + 1
|
||||||
) then (
|
FROM decks
|
||||||
select
|
|
||||||
max(id) + 1
|
|
||||||
from decks
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end;
|
END;
|
|
@ -1,9 +1,7 @@
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM cards
|
||||||
from cards
|
WHERE did = ?1
|
||||||
where
|
OR (
|
||||||
did = ?1
|
|
||||||
or (
|
|
||||||
odid != 0
|
odid != 0
|
||||||
and odid = ?1
|
AND odid = ?1
|
||||||
)
|
)
|
|
@ -1,41 +1,41 @@
|
||||||
select did,
|
SELECT did,
|
||||||
sum(queue = :new_queue),
|
sum(queue = :new_queue),
|
||||||
sum(
|
sum(
|
||||||
queue = :review_queue
|
queue = :review_queue
|
||||||
and due <= :day_cutoff
|
AND due <= :day_cutoff
|
||||||
),
|
),
|
||||||
-- learning
|
-- learning
|
||||||
sum(
|
sum(
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
:sched_ver
|
:sched_ver
|
||||||
when 2 then (
|
WHEN 2 THEN (
|
||||||
-- v2 scheduler
|
-- v2 scheduler
|
||||||
(
|
(
|
||||||
queue = :learn_queue
|
queue = :learn_queue
|
||||||
and due < :learn_cutoff
|
AND due < :learn_cutoff
|
||||||
)
|
)
|
||||||
or (
|
OR (
|
||||||
queue = :daylearn_queue
|
queue = :daylearn_queue
|
||||||
and due <= :day_cutoff
|
AND due <= :day_cutoff
|
||||||
)
|
)
|
||||||
or (
|
OR (
|
||||||
queue = :preview_queue
|
queue = :preview_queue
|
||||||
and due <= :learn_cutoff
|
AND due <= :learn_cutoff
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else (
|
ELSE (
|
||||||
-- v1 scheduler
|
-- v1 scheduler
|
||||||
case
|
CASE
|
||||||
when queue = :learn_queue
|
WHEN queue = :learn_queue
|
||||||
and due < :learn_cutoff then left / 1000
|
AND due < :learn_cutoff THEN left / 1000
|
||||||
when queue = :daylearn_queue
|
WHEN queue = :daylearn_queue
|
||||||
and due <= :day_cutoff then 1
|
AND due <= :day_cutoff THEN 1
|
||||||
else 0
|
ELSE 0
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
from cards
|
FROM cards
|
||||||
where queue >= 0
|
WHERE queue >= 0
|
|
@ -1,8 +1,7 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
common,
|
common,
|
||||||
kind
|
kind
|
||||||
from decks
|
FROM decks
|
|
@ -1,9 +1,6 @@
|
||||||
select
|
SELECT DISTINCT did
|
||||||
distinct did
|
FROM cards
|
||||||
from cards
|
WHERE did NOT IN (
|
||||||
where
|
SELECT id
|
||||||
did not in (
|
FROM decks
|
||||||
select
|
|
||||||
id
|
|
||||||
from decks
|
|
||||||
);
|
);
|
|
@ -1,8 +1,8 @@
|
||||||
insert into active_decks
|
INSERT INTO active_decks
|
||||||
select id
|
SELECT id
|
||||||
from decks
|
FROM decks
|
||||||
where name = ?
|
WHERE name = ?
|
||||||
or (
|
OR (
|
||||||
name >= ?
|
name >= ?
|
||||||
and name < ?
|
AND name < ?
|
||||||
)
|
)
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into decks (id, name, mtime_secs, usn, common, kind)
|
OR REPLACE INTO decks (id, name, mtime_secs, usn, common, kind)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?, ?)
|
|
|
@ -1,19 +1,16 @@
|
||||||
insert into deck_config (id, name, mtime_secs, usn, config)
|
INSERT INTO deck_config (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM deck_config
|
||||||
from deck_config
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM deck_config
|
||||||
max(id) + 1
|
|
||||||
from deck_config
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into deck_config (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO deck_config (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?);
|
||||||
(?, ?, ?, ?, ?);
|
|
|
@ -1,7 +1,6 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from deck_config
|
FROM deck_config
|
|
@ -1,8 +1,6 @@
|
||||||
update deck_config
|
UPDATE deck_config
|
||||||
set
|
SET name = ?,
|
||||||
name = ?,
|
|
||||||
mtime_secs = ?,
|
mtime_secs = ?,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
config = ?
|
config = ?
|
||||||
where
|
WHERE id = ?;
|
||||||
id = ?;
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into graves (usn, oid, type)
|
OR IGNORE INTO graves (usn, oid, type)
|
||||||
values
|
VALUES (?, ?, ?)
|
||||||
(?, ?, ?)
|
|
|
@ -1,4 +1,4 @@
|
||||||
insert into notes (
|
INSERT INTO notes (
|
||||||
id,
|
id,
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
|
@ -11,21 +11,18 @@ insert into notes (
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notes
|
||||||
from notes
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM notes
|
||||||
max(id) + 1
|
|
||||||
from notes
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notes (
|
OR REPLACE INTO notes (
|
||||||
id,
|
id,
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
|
@ -12,8 +12,7 @@ insert
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
mod,
|
mod,
|
||||||
usn,
|
usn,
|
||||||
tags,
|
tags,
|
||||||
flds
|
flds
|
||||||
from notes
|
FROM notes
|
|
@ -1,5 +1,3 @@
|
||||||
select
|
SELECT COUNT(id) = 0
|
||||||
count(id) = 0
|
FROM cards
|
||||||
from cards
|
WHERE nid = ?;
|
||||||
where
|
|
||||||
nid = ?;
|
|
|
@ -1,6 +1,5 @@
|
||||||
update notes
|
UPDATE notes
|
||||||
set
|
SET guid = ?,
|
||||||
guid = ?,
|
|
||||||
mid = ?,
|
mid = ?,
|
||||||
mod = ?,
|
mod = ?,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
|
@ -8,5 +7,4 @@ set
|
||||||
flds = ?,
|
flds = ?,
|
||||||
sfld = ?,
|
sfld = ?,
|
||||||
csum = ?
|
csum = ?
|
||||||
where
|
WHERE id = ?
|
||||||
id = ?
|
|
|
@ -1,19 +1,16 @@
|
||||||
insert into notetypes (id, name, mtime_secs, usn, config)
|
INSERT INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notetypes
|
||||||
from notetypes
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM notetypes
|
||||||
max(id) + 1
|
|
||||||
from notetypes
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?);
|
||||||
(?, ?, ?, ?, ?);
|
|
|
@ -1,10 +1,7 @@
|
||||||
delete from cards
|
DELETE FROM cards
|
||||||
where
|
WHERE nid IN (
|
||||||
nid in (
|
SELECT id
|
||||||
select
|
FROM notes
|
||||||
id
|
WHERE mid = ?
|
||||||
from notes
|
|
||||||
where
|
|
||||||
mid = ?
|
|
||||||
)
|
)
|
||||||
and ord = ?;
|
AND ord = ?;
|
|
@ -1,27 +1,26 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
nid,
|
nid,
|
||||||
ord,
|
ord,
|
||||||
-- original deck
|
-- original deck
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
odid
|
odid
|
||||||
when 0 then did
|
WHEN 0 THEN did
|
||||||
else odid
|
ELSE odid
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
-- new position if card is empty
|
-- new position if card is empty
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
type
|
type
|
||||||
when 0 then (
|
WHEN 0 THEN (
|
||||||
case
|
CASE
|
||||||
odue
|
odue
|
||||||
when 0 then max(0, due)
|
WHEN 0 THEN max(0, due)
|
||||||
else max(odue, 0)
|
ELSE max(odue, 0)
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
else null
|
ELSE NULL
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
from cards c
|
FROM cards c
|
|
@ -1,10 +1,6 @@
|
||||||
select
|
SELECT DISTINCT name
|
||||||
distinct name
|
FROM FIELDS
|
||||||
from fields
|
WHERE ntid IN (
|
||||||
where
|
SELECT mid
|
||||||
ntid in (
|
FROM notes
|
||||||
select
|
WHERE id IN
|
||||||
mid
|
|
||||||
from notes
|
|
||||||
where
|
|
||||||
id in
|
|
|
@ -1,9 +1,6 @@
|
||||||
select
|
SELECT ord,
|
||||||
ord,
|
|
||||||
name,
|
name,
|
||||||
config
|
config
|
||||||
from fields
|
FROM FIELDS
|
||||||
where
|
WHERE ntid = ?
|
||||||
ntid = ?
|
ORDER BY ord
|
||||||
order by
|
|
||||||
ord
|
|
|
@ -1,7 +1,6 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from notetypes
|
FROM notetypes
|
|
@ -1,4 +1,3 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name
|
name
|
||||||
from notetypes
|
FROM notetypes
|
|
@ -1,11 +1,8 @@
|
||||||
select
|
SELECT ord,
|
||||||
ord,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from templates
|
FROM templates
|
||||||
where
|
WHERE ntid = ?
|
||||||
ntid = ?
|
ORDER BY ord
|
||||||
order by
|
|
||||||
ord
|
|
|
@ -1,13 +1,9 @@
|
||||||
select
|
SELECT nt.id,
|
||||||
nt.id,
|
|
||||||
nt.name,
|
nt.name,
|
||||||
(
|
(
|
||||||
select
|
SELECT COUNT(*)
|
||||||
count(*)
|
FROM notes n
|
||||||
from notes n
|
WHERE nt.id = n.mid
|
||||||
where
|
|
||||||
nt.id = n.mid
|
|
||||||
)
|
)
|
||||||
from notetypes nt
|
FROM notetypes nt
|
||||||
order by
|
ORDER BY nt.name
|
||||||
nt.name
|
|
|
@ -1,7 +1,7 @@
|
||||||
select coalesce(max(ord), 0)
|
SELECT coalesce(max(ord), 0)
|
||||||
from cards
|
FROM cards
|
||||||
where nid in (
|
WHERE nid IN (
|
||||||
select id
|
SELECT id
|
||||||
from notes
|
FROM notes
|
||||||
where mid = ?
|
WHERE mid = ?
|
||||||
)
|
)
|
|
@ -1,3 +1,2 @@
|
||||||
insert into fields (ntid, ord, name, config)
|
INSERT INTO FIELDS (ntid, ord, name, config)
|
||||||
values
|
VALUES (?, ?, ?, ?);
|
||||||
(?, ?, ?, ?);
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetype_config (ntid, config)
|
OR REPLACE INTO notetype_config (ntid, config)
|
||||||
values
|
VALUES (?, ?)
|
||||||
(?, ?)
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?)
|
|
|
@ -1,3 +1,2 @@
|
||||||
insert into templates (ntid, ord, name, mtime_secs, usn, config)
|
INSERT INTO templates (ntid, ord, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?, ?)
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into revlog (
|
OR IGNORE INTO revlog (
|
||||||
id,
|
id,
|
||||||
cid,
|
cid,
|
||||||
usn,
|
usn,
|
||||||
|
@ -10,18 +10,18 @@ insert
|
||||||
time,
|
time,
|
||||||
type
|
type
|
||||||
)
|
)
|
||||||
values (
|
VALUES (
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select id
|
SELECT id
|
||||||
from revlog
|
FROM revlog
|
||||||
) then (
|
) THEN (
|
||||||
select max(id) + 1
|
SELECT max(id) + 1
|
||||||
from revlog
|
FROM revlog
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
update revlog
|
UPDATE revlog
|
||||||
set ivl = min(max(round(ivl), -2147483648), 2147483647),
|
SET ivl = min(max(round(ivl), -2147483648), 2147483647),
|
||||||
lastIvl = min(max(round(lastIvl), -2147483648), 2147483647),
|
lastIvl = min(max(round(lastIvl), -2147483648), 2147483647),
|
||||||
time = min(max(round(time), 0), 2147483647)
|
time = min(max(round(time), 0), 2147483647)
|
||||||
where ivl != min(max(round(ivl), -2147483648), 2147483647)
|
WHERE ivl != min(max(round(ivl), -2147483648), 2147483647)
|
||||||
or lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
OR lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
||||||
or time != min(max(round(time), 0), 2147483647)
|
OR time != min(max(round(time), 0), 2147483647)
|
|
@ -1,5 +1,4 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
cid,
|
cid,
|
||||||
usn,
|
usn,
|
||||||
ease,
|
ease,
|
||||||
|
@ -8,4 +7,4 @@ select
|
||||||
factor,
|
factor,
|
||||||
time,
|
time,
|
||||||
type
|
type
|
||||||
from revlog
|
FROM revlog
|
|
@ -1,5 +1,5 @@
|
||||||
select count(),
|
SELECT COUNT(),
|
||||||
coalesce(sum(time) / 1000.0, 0.0)
|
coalesce(sum(time) / 1000.0, 0.0)
|
||||||
from revlog
|
FROM revlog
|
||||||
where id > ?
|
WHERE id > ?
|
||||||
and type != ?
|
AND type != ?
|
|
@ -1,88 +1,92 @@
|
||||||
create table col
|
CREATE TABLE col (
|
||||||
(
|
id integer PRIMARY KEY,
|
||||||
id integer primary key,
|
crt integer NOT NULL,
|
||||||
crt integer not null,
|
mod integer NOT NULL,
|
||||||
mod integer not null,
|
scm integer NOT NULL,
|
||||||
scm integer not null,
|
ver integer NOT NULL,
|
||||||
ver integer not null,
|
dty integer NOT NULL,
|
||||||
dty integer not null,
|
usn integer NOT NULL,
|
||||||
usn integer not null,
|
ls integer NOT NULL,
|
||||||
ls integer not null,
|
conf text NOT NULL,
|
||||||
conf text not null,
|
models text NOT NULL,
|
||||||
models text not null,
|
decks text NOT NULL,
|
||||||
decks text not null,
|
dconf text NOT NULL,
|
||||||
dconf text not null,
|
tags text NOT NULL
|
||||||
tags text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE notes (
|
||||||
create table notes
|
id integer PRIMARY KEY,
|
||||||
(
|
guid text NOT NULL,
|
||||||
id integer primary key,
|
mid integer NOT NULL,
|
||||||
guid text not null,
|
mod integer NOT NULL,
|
||||||
mid integer not null,
|
usn integer NOT NULL,
|
||||||
mod integer not null,
|
tags text NOT NULL,
|
||||||
usn integer not null,
|
flds text NOT NULL,
|
||||||
tags text not null,
|
sfld integer NOT NULL,
|
||||||
flds text not null,
|
csum integer NOT NULL,
|
||||||
sfld integer not null,
|
flags integer NOT NULL,
|
||||||
csum integer not null,
|
data text NOT NULL
|
||||||
flags integer not null,
|
|
||||||
data text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE cards (
|
||||||
create table cards
|
id integer PRIMARY KEY,
|
||||||
(
|
nid integer NOT NULL,
|
||||||
id integer primary key,
|
did integer NOT NULL,
|
||||||
nid integer not null,
|
ord integer NOT NULL,
|
||||||
did integer not null,
|
mod integer NOT NULL,
|
||||||
ord integer not null,
|
usn integer NOT NULL,
|
||||||
mod integer not null,
|
type integer NOT NULL,
|
||||||
usn integer not null,
|
queue integer NOT NULL,
|
||||||
type integer not null,
|
due integer NOT NULL,
|
||||||
queue integer not null,
|
ivl integer NOT NULL,
|
||||||
due integer not null,
|
factor integer NOT NULL,
|
||||||
ivl integer not null,
|
reps integer NOT NULL,
|
||||||
factor integer not null,
|
lapses integer NOT NULL,
|
||||||
reps integer not null,
|
left integer NOT NULL,
|
||||||
lapses integer not null,
|
odue integer NOT NULL,
|
||||||
left integer not null,
|
odid integer NOT NULL,
|
||||||
odue integer not null,
|
flags integer NOT NULL,
|
||||||
odid integer not null,
|
data text NOT NULL
|
||||||
flags integer not null,
|
|
||||||
data text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE revlog (
|
||||||
create table revlog
|
id integer PRIMARY KEY,
|
||||||
(
|
cid integer NOT NULL,
|
||||||
id integer primary key,
|
usn integer NOT NULL,
|
||||||
cid integer not null,
|
ease integer NOT NULL,
|
||||||
usn integer not null,
|
ivl integer NOT NULL,
|
||||||
ease integer not null,
|
lastIvl integer NOT NULL,
|
||||||
ivl integer not null,
|
factor integer NOT NULL,
|
||||||
lastIvl integer not null,
|
time integer NOT NULL,
|
||||||
factor integer not null,
|
type integer NOT NULL
|
||||||
time integer not null,
|
|
||||||
type integer not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE graves (
|
||||||
create table graves
|
usn integer NOT NULL,
|
||||||
(
|
oid integer NOT NULL,
|
||||||
usn integer not null,
|
type integer NOT NULL
|
||||||
oid integer not null,
|
|
||||||
type integer not null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- syncing
|
-- syncing
|
||||||
create index ix_notes_usn on notes (usn);
|
CREATE INDEX ix_notes_usn ON notes (usn);
|
||||||
create index ix_cards_usn on cards (usn);
|
CREATE INDEX ix_cards_usn ON cards (usn);
|
||||||
create index ix_revlog_usn on revlog (usn);
|
CREATE INDEX ix_revlog_usn ON revlog (usn);
|
||||||
-- card spacing, etc
|
-- card spacing, etc
|
||||||
create index ix_cards_nid on cards (nid);
|
CREATE INDEX ix_cards_nid ON cards (nid);
|
||||||
-- scheduling and deck limiting
|
-- 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
|
-- revlog by card
|
||||||
create index ix_revlog_cid on revlog (cid);
|
CREATE INDEX ix_revlog_cid ON revlog (cid);
|
||||||
-- field uniqueness
|
-- field uniqueness
|
||||||
create index ix_notes_csum on notes (csum);
|
CREATE INDEX ix_notes_csum ON notes (csum);
|
||||||
|
INSERT INTO col
|
||||||
insert into col values (1,0,0,0,0,0,0,0,'{}','{}','{}','{}','{}');
|
VALUES (
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}'
|
||||||
|
);
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into tags (tag, usn)
|
OR IGNORE INTO tags (tag, usn)
|
||||||
values
|
VALUES (?, ?)
|
||||||
(?, ?)
|
|
|
@ -1,12 +1,11 @@
|
||||||
drop table config;
|
DROP TABLE config;
|
||||||
drop table deck_config;
|
DROP TABLE deck_config;
|
||||||
drop table tags;
|
DROP TABLE tags;
|
||||||
drop table fields;
|
DROP TABLE FIELDS;
|
||||||
drop table templates;
|
DROP TABLE templates;
|
||||||
drop table notetypes;
|
DROP TABLE notetypes;
|
||||||
drop table decks;
|
DROP TABLE decks;
|
||||||
drop index idx_cards_odid;
|
DROP INDEX idx_cards_odid;
|
||||||
drop index idx_notes_mid;
|
DROP INDEX idx_notes_mid;
|
||||||
update col
|
UPDATE col
|
||||||
set
|
SET ver = 11;
|
||||||
ver = 11;
|
|
|
@ -1,20 +1,19 @@
|
||||||
create table deck_config (
|
CREATE TABLE deck_config (
|
||||||
id integer primary key not null,
|
id integer PRIMARY KEY NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null
|
config blob NOT NULL
|
||||||
);
|
);
|
||||||
create table config (
|
CREATE TABLE config (
|
||||||
key text not null primary key,
|
KEY text NOT NULL PRIMARY KEY,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
val blob not null
|
val blob NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create table tags (
|
CREATE TABLE tags (
|
||||||
tag text not null primary key collate unicase,
|
tag text NOT NULL PRIMARY KEY COLLATE unicase,
|
||||||
usn integer not null
|
usn integer NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
update col
|
UPDATE col
|
||||||
set
|
SET ver = 14;
|
||||||
ver = 14;
|
|
|
@ -1,45 +1,43 @@
|
||||||
create table fields (
|
CREATE TABLE FIELDS (
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
config blob not null,
|
config blob NOT NULL,
|
||||||
primary key (ntid, ord)
|
PRIMARY KEY (ntid, ord)
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create unique index idx_fields_name_ntid on fields (name, ntid);
|
CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid);
|
||||||
create table templates (
|
CREATE TABLE templates (
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null,
|
config blob NOT NULL,
|
||||||
primary key (ntid, ord)
|
PRIMARY KEY (ntid, ord)
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create unique index idx_templates_name_ntid on templates (name, ntid);
|
CREATE UNIQUE INDEX idx_templates_name_ntid ON templates (name, ntid);
|
||||||
create index idx_templates_usn on templates (usn);
|
CREATE INDEX idx_templates_usn ON templates (usn);
|
||||||
create table notetypes (
|
CREATE TABLE notetypes (
|
||||||
id integer not null primary key,
|
id integer NOT NULL PRIMARY KEY,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null
|
config blob NOT NULL
|
||||||
);
|
);
|
||||||
create unique index idx_notetypes_name on notetypes (name);
|
CREATE UNIQUE INDEX idx_notetypes_name ON notetypes (name);
|
||||||
create index idx_notetypes_usn on notetypes (usn);
|
CREATE INDEX idx_notetypes_usn ON notetypes (usn);
|
||||||
create table decks (
|
CREATE TABLE decks (
|
||||||
id integer primary key not null,
|
id integer PRIMARY KEY NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
common blob not null,
|
common blob NOT NULL,
|
||||||
kind blob not null
|
kind blob NOT NULL
|
||||||
);
|
);
|
||||||
create unique index idx_decks_name on decks (name);
|
CREATE UNIQUE INDEX idx_decks_name ON decks (name);
|
||||||
create index idx_notes_mid on notes (mid);
|
CREATE INDEX idx_notes_mid ON notes (mid);
|
||||||
create index idx_cards_odid on cards (odid)
|
CREATE INDEX idx_cards_odid ON cards (odid)
|
||||||
where
|
WHERE odid != 0;
|
||||||
odid != 0;
|
UPDATE col
|
||||||
update col
|
SET ver = 15;
|
||||||
set
|
ANALYZE;
|
||||||
ver = 15;
|
|
||||||
analyze;
|
|
|
@ -1,7 +1,18 @@
|
||||||
load("//ts:prettier.bzl", "prettier")
|
load("//ts:prettier.bzl", "prettier", "prettier_test")
|
||||||
|
load("//ts:sql_format.bzl", "sql_format_setup")
|
||||||
|
|
||||||
prettier()
|
prettier()
|
||||||
|
|
||||||
|
prettier_test(
|
||||||
|
name = "format_check",
|
||||||
|
srcs = glob([
|
||||||
|
"*.ts",
|
||||||
|
"*.js",
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
|
||||||
|
sql_format_setup()
|
||||||
|
|
||||||
# Exported files
|
# Exported files
|
||||||
#################
|
#################
|
||||||
|
|
||||||
|
@ -12,6 +23,7 @@ exports_files([
|
||||||
"rollup.config.js",
|
"rollup.config.js",
|
||||||
".eslintrc.js",
|
".eslintrc.js",
|
||||||
"licenses.json",
|
"licenses.json",
|
||||||
|
"sql_format.ts",
|
||||||
])
|
])
|
||||||
|
|
||||||
alias(
|
alias(
|
||||||
|
|
|
@ -197,7 +197,7 @@ export function renderCards(
|
||||||
|
|
||||||
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
x.range([bounds.marginLeft, bounds.width - bounds.marginRight]);
|
||||||
|
|
||||||
const tableData = (data as any).flatMap((d: SummedDatum, idx: number) => {
|
const tableData = data.flatMap((d: SummedDatum, idx: number) => {
|
||||||
const percent = ((d.count / xMax) * 100).toFixed(1);
|
const percent = ((d.count / xMax) * 100).toFixed(1);
|
||||||
return d.show
|
return d.show
|
||||||
? ({
|
? ({
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import type pb from "anki/backend_proto";
|
import type pb from "anki/backend_proto";
|
||||||
import { extent, histogram, sum } from "d3-array";
|
import { extent, histogram, sum } from "d3-array";
|
||||||
import { scaleLinear, scaleSequential } from "d3-scale";
|
import { scaleLinear, scaleSequential } from "d3-scale";
|
||||||
import { CardQueue } from "anki/cards";
|
import { CardType } from "anki/cards";
|
||||||
import type { HistogramData } from "./histogram-graph";
|
import type { HistogramData } from "./histogram-graph";
|
||||||
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
import { interpolateRdYlGn } from "d3-scale-chromatic";
|
||||||
import type { I18n } from "anki/i18n";
|
import type { I18n } from "anki/i18n";
|
||||||
|
@ -21,7 +21,7 @@ export interface GraphData {
|
||||||
|
|
||||||
export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
export function gatherData(data: pb.BackendProto.GraphsOut): GraphData {
|
||||||
const eases = (data.cards as pb.BackendProto.Card[])
|
const eases = (data.cards as pb.BackendProto.Card[])
|
||||||
.filter((c) => c.queue == CardQueue.Review)
|
.filter((c) => [CardType.Review, CardType.Relearn].includes(c.ctype))
|
||||||
.map((c) => c.easeFactor / 10);
|
.map((c) => c.easeFactor / 10);
|
||||||
return { eases };
|
return { eases };
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,33 +67,48 @@ export function prepareIntervalData(
|
||||||
return [null, []];
|
return [null, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
const [_xMinOrig, origXMax] = extent(allIntervals);
|
const xMin = 0;
|
||||||
let xMax = origXMax;
|
let [, xMax] = extent(allIntervals);
|
||||||
|
let niceNecessary = false;
|
||||||
|
|
||||||
// cap max to selected range
|
// cap max to selected range
|
||||||
switch (range) {
|
switch (range) {
|
||||||
case IntervalRange.Month:
|
case IntervalRange.Month:
|
||||||
xMax = Math.min(xMax!, 31);
|
xMax = Math.min(xMax!, 30);
|
||||||
break;
|
break;
|
||||||
case IntervalRange.Percentile50:
|
case IntervalRange.Percentile50:
|
||||||
xMax = quantile(allIntervals, 0.5);
|
xMax = quantile(allIntervals, 0.5);
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
case IntervalRange.Percentile95:
|
case IntervalRange.Percentile95:
|
||||||
xMax = quantile(allIntervals, 0.95);
|
xMax = quantile(allIntervals, 0.95);
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
case IntervalRange.All:
|
case IntervalRange.All:
|
||||||
|
niceNecessary = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const xMin = 0;
|
|
||||||
xMax = xMax! + 1;
|
xMax = xMax! + 1;
|
||||||
|
|
||||||
|
// do not show the zero interval
|
||||||
|
const increment = (x: number): number => x + 1;
|
||||||
|
|
||||||
|
const adjustTicks = (x: number, idx: number, ticks: number[]): number[] =>
|
||||||
|
idx === ticks.length - 1 ? [x - (ticks[0] - 1), x + 1] : [x - (ticks[0] - 1)];
|
||||||
|
|
||||||
// cap bars to available range
|
// cap bars to available range
|
||||||
const desiredBars = Math.min(70, xMax! - xMin!);
|
const desiredBars = Math.min(70, xMax! - xMin!);
|
||||||
|
|
||||||
const scale = scaleLinear().domain([xMin!, xMax!]).nice();
|
const prescale = scaleLinear().domain([xMin!, xMax!]);
|
||||||
|
|
||||||
|
const scale = scaleLinear().domain(
|
||||||
|
(niceNecessary ? prescale.nice() : prescale).domain().map(increment)
|
||||||
|
);
|
||||||
|
|
||||||
const bins = histogram()
|
const bins = histogram()
|
||||||
.domain(scale.domain() as any)
|
.domain(scale.domain() as [number, number])
|
||||||
.thresholds(scale.ticks(desiredBars))(allIntervals);
|
.thresholds(scale.ticks(desiredBars).flatMap(adjustTicks))(allIntervals);
|
||||||
|
|
||||||
// empty graph?
|
// empty graph?
|
||||||
const totalInPeriod = sum(bins, (bin) => bin.length);
|
const totalInPeriod = sum(bins, (bin) => bin.length);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"@pyoner/svelte-types": "^3.4.4-2",
|
"@pyoner/svelte-types": "^3.4.4-2",
|
||||||
"@rollup/plugin-commonjs": "^15.1.0",
|
"@rollup/plugin-commonjs": "^15.1.0",
|
||||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||||
|
"@sqltools/formatter": "^1.2.2",
|
||||||
"@tsconfig/svelte": "^1.0.10",
|
"@tsconfig/svelte": "^1.0.10",
|
||||||
"@types/d3-array": "^2.0.0",
|
"@types/d3-array": "^2.0.0",
|
||||||
"@types/d3-axis": "^1.0.12",
|
"@types/d3-axis": "^1.0.12",
|
||||||
|
@ -22,15 +23,18 @@
|
||||||
"@types/d3-shape": "^1.3.2",
|
"@types/d3-shape": "^1.3.2",
|
||||||
"@types/d3-time": "^2.0.0",
|
"@types/d3-time": "^2.0.0",
|
||||||
"@types/d3-transition": "^1.1.6",
|
"@types/d3-transition": "^1.1.6",
|
||||||
|
"@types/diff": "^5.0.0",
|
||||||
"@types/jquery": "^3.5.0",
|
"@types/jquery": "^3.5.0",
|
||||||
"@types/jqueryui": "^1.12.13",
|
"@types/jqueryui": "^1.12.13",
|
||||||
"@types/lodash": "^4.14.162",
|
"@types/lodash": "^4.14.162",
|
||||||
"@types/long": "^4.0.1",
|
"@types/long": "^4.0.1",
|
||||||
|
"@types/node": "^14.14.20",
|
||||||
"@types/react": "^16.9.53",
|
"@types/react": "^16.9.53",
|
||||||
"@types/react-dom": "^16.9.8",
|
"@types/react-dom": "^16.9.8",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.11.0",
|
"@typescript-eslint/eslint-plugin": "^2.11.0",
|
||||||
"@typescript-eslint/parser": "^2.11.0",
|
"@typescript-eslint/parser": "^2.11.0",
|
||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
|
"diff": "^5.0.0",
|
||||||
"eslint": "^6.7.2",
|
"eslint": "^6.7.2",
|
||||||
"license-checker-rseidelsohn": "=1.1.2",
|
"license-checker-rseidelsohn": "=1.1.2",
|
||||||
"patch-package": "^6.2.2",
|
"patch-package": "^6.2.2",
|
||||||
|
|
24
ts/sql_format.bzl
Normal file
24
ts/sql_format.bzl
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
load("@npm//@bazel/typescript:index.bzl", "ts_library")
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
|
||||||
|
|
||||||
|
def sql_format_setup():
|
||||||
|
ts_library(
|
||||||
|
name = "sql_format_lib",
|
||||||
|
srcs = ["//ts:sql_format.ts"],
|
||||||
|
deps = [
|
||||||
|
"@npm//@sqltools/formatter",
|
||||||
|
"@npm//@types/node",
|
||||||
|
"@npm//@types/diff",
|
||||||
|
"@npm//diff",
|
||||||
|
],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def sql_format(name = "sql_format", srcs = [], **kwargs):
|
||||||
|
nodejs_test(
|
||||||
|
name = name,
|
||||||
|
entry_point = "//ts:sql_format.ts",
|
||||||
|
args = [native.package_name() + "/" + f for f in srcs],
|
||||||
|
data = ["//ts:sql_format_lib", "@npm//tslib", "@npm//diff"] + srcs,
|
||||||
|
**kwargs
|
||||||
|
)
|
46
ts/sql_format.ts
Normal file
46
ts/sql_format.ts
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import sqlFormatter from "@sqltools/formatter";
|
||||||
|
import * as Diff from "diff";
|
||||||
|
import process from "process";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
const workspace = process.env.BUILD_WORKSPACE_DIRECTORY;
|
||||||
|
const wantFix = workspace !== undefined;
|
||||||
|
|
||||||
|
function fixFile(relpath: string, newText: string): void {
|
||||||
|
const workspacePath = path.join(workspace!, relpath);
|
||||||
|
fs.writeFileSync(workspacePath, newText);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatText(text: string): string {
|
||||||
|
const newText: string = sqlFormatter.format(text, {
|
||||||
|
indent: " ",
|
||||||
|
reservedWordCase: "upper",
|
||||||
|
});
|
||||||
|
// 'type' is treated as a reserved word, but Anki uses it in various sql
|
||||||
|
// tables, so we don't want it uppercased
|
||||||
|
return newText.replace(/\bTYPE\b/g, "type");
|
||||||
|
}
|
||||||
|
|
||||||
|
let errorFound = false;
|
||||||
|
for (const path of process.argv.slice(2)) {
|
||||||
|
const orig = fs.readFileSync(path).toString();
|
||||||
|
const formatted = formatText(orig);
|
||||||
|
if (orig !== formatted) {
|
||||||
|
if (wantFix) {
|
||||||
|
fixFile(path, formatted);
|
||||||
|
console.log(`Fixed ${path}`);
|
||||||
|
} else {
|
||||||
|
if (!errorFound) {
|
||||||
|
errorFound = true;
|
||||||
|
console.log("SQL formatting issues found:");
|
||||||
|
}
|
||||||
|
console.log(Diff.createPatch(path, orig, formatted));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (errorFound) {
|
||||||
|
console.log("Use 'bazel run //rslib:sql_format' to fix.");
|
||||||
|
console.log(process.env.BUILD_WORKSPACE_DIRECTORY);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "es6",
|
"module": "es6",
|
||||||
"lib": ["es2016", "dom"],
|
"lib": ["es2016", "es2019.array", "dom"],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"anki/*": ["../bazel-bin/ts/lib/*"]
|
"anki/*": ["../bazel-bin/ts/lib/*"]
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||||
"jsx": "react",
|
"jsx": "react",
|
||||||
"types": ["svelte", "long"],
|
"types": ["svelte", "long", "node"],
|
||||||
"noEmitHelpers": true,
|
"noEmitHelpers": true,
|
||||||
"importHelpers": true
|
"importHelpers": true
|
||||||
}
|
}
|
||||||
|
|
20
ts/yarn.lock
20
ts/yarn.lock
|
@ -145,6 +145,11 @@
|
||||||
estree-walker "^1.0.1"
|
estree-walker "^1.0.1"
|
||||||
picomatch "^2.2.2"
|
picomatch "^2.2.2"
|
||||||
|
|
||||||
|
"@sqltools/formatter@^1.2.2":
|
||||||
|
version "1.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sqltools/formatter/-/formatter-1.2.2.tgz#9390a8127c0dcba61ebd7fdcc748655e191bdd68"
|
||||||
|
integrity sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q==
|
||||||
|
|
||||||
"@tsconfig/svelte@^1.0.10":
|
"@tsconfig/svelte@^1.0.10":
|
||||||
version "1.0.10"
|
version "1.0.10"
|
||||||
resolved "https://registry.yarnpkg.com/@tsconfig/svelte/-/svelte-1.0.10.tgz#30ec7feeee0bdf38b12a50f0686f8a2e7b6b9dc0"
|
resolved "https://registry.yarnpkg.com/@tsconfig/svelte/-/svelte-1.0.10.tgz#30ec7feeee0bdf38b12a50f0686f8a2e7b6b9dc0"
|
||||||
|
@ -220,6 +225,11 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/d3-selection" "^1"
|
"@types/d3-selection" "^1"
|
||||||
|
|
||||||
|
"@types/diff@^5.0.0":
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-5.0.0.tgz#eb71e94feae62548282c4889308a3dfb57e36020"
|
||||||
|
integrity sha512-jrm2K65CokCCX4NmowtA+MfXyuprZC13jbRuwprs6/04z/EcFg/MCwYdsHn+zgV4CQBiATiI7AEq7y1sZCtWKA==
|
||||||
|
|
||||||
"@types/eslint-visitor-keys@^1.0.0":
|
"@types/eslint-visitor-keys@^1.0.0":
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
resolved "https://registry.yarnpkg.com/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#1ee30d79544ca84d68d4b3cdb0af4f205663dd2d"
|
||||||
|
@ -279,6 +289,11 @@
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.38.tgz#66a7c068305dbd64cf167d0f6b6b6be71dd453e1"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-13.13.38.tgz#66a7c068305dbd64cf167d0f6b6b6be71dd453e1"
|
||||||
integrity sha512-oxo8j9doh7ab9NwDA9bCeFfjHRF/uzk+fTljCy8lMjZ3YzZGAXNDKhTE3Byso/oy32UTUQIXB3HCVHu3d2T3xg==
|
integrity sha512-oxo8j9doh7ab9NwDA9bCeFfjHRF/uzk+fTljCy8lMjZ3YzZGAXNDKhTE3Byso/oy32UTUQIXB3HCVHu3d2T3xg==
|
||||||
|
|
||||||
|
"@types/node@^14.14.20":
|
||||||
|
version "14.14.20"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.20.tgz#f7974863edd21d1f8a494a73e8e2b3658615c340"
|
||||||
|
integrity sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==
|
||||||
|
|
||||||
"@types/prop-types@*":
|
"@types/prop-types@*":
|
||||||
version "15.7.3"
|
version "15.7.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
||||||
|
@ -959,6 +974,11 @@ dezalgo@^1.0.0:
|
||||||
asap "^2.0.0"
|
asap "^2.0.0"
|
||||||
wrappy "1"
|
wrappy "1"
|
||||||
|
|
||||||
|
diff@^5.0.0:
|
||||||
|
version "5.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
|
||||||
|
integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==
|
||||||
|
|
||||||
doctrine@^3.0.0:
|
doctrine@^3.0.0:
|
||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
|
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
|
||||||
|
|
Loading…
Reference in a new issue