CREATE TABLE IF NOT EXISTS TodoItemEntity (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    orderNum INTEGER NOT NULL,
    text TEXT NOT NULL,
    isDone INTEGER AS Boolean NOT NULL DEFAULT 0
);

selectAll:
SELECT *
FROM TodoItemEntity;

select:
SELECT *
FROM TodoItemEntity
WHERE id = :id;

add:
INSERT INTO TodoItemEntity (orderNum, text)
VALUES ((CASE (SELECT COUNT(*) FROM TodoItemEntity) WHEN 0 THEN 1 ELSE (SELECT MAX(orderNum)+1 FROM TodoItemEntity) END), :text);

setText:
UPDATE TodoItemEntity
SET text = :text
WHERE id = :id;

setDone:
UPDATE TodoItemEntity
SET isDone = :isDone
WHERE id = :id;

delete:
DELETE FROM TodoItemEntity
WHERE id = :id;

getLastInsertId:
SELECT last_insert_rowid();

clear:
DELETE FROM TodoItemEntity;
