CREATE TABLE folderEntity (
  id TEXT PRIMARY KEY,
  parent_id TEXT NOT NULL,
  user_id TEXT NOT NULL,
  title TEXT NOT NULL,
  created_at INTEGER NOT NULL,
  last_updated_at INTEGER NOT NULL,
  last_synced_at INTEGER,
  favorite INTEGER NOT NULL,
  icon TEXT,
  icon_tint INTEGER
);

query:
SELECT *
FROM folderEntity
WHERE title LIKE '%' || ? || '%'
ORDER BY last_updated_at
LIMIT 10;

getLastUpdated:
SELECT *
FROM folderEntity
ORDER BY last_updated_at;

selectAllFolders:
SELECT *
FROM folderEntity;

selectByUserId:
SELECT *
FROM folderEntity
WHERE folderEntity.user_id = ?;

selectByUserIdAfterTime:
SELECT *
FROM folderEntity
WHERE folderEntity.user_id = ? AND last_updated_at > ?;

selectChildrenFolder:
SELECT *
FROM folderEntity
WHERE folderEntity.parent_id = ?;

selectFolderById:
SELECT *
FROM folderEntity
WHERE folderEntity.id = ?;

countAllFolderItems:
SELECT parent_id, COUNT(id)
FROM folderEntity
GROUP BY parent_id;

countAllDocumentItems:
SELECT parent_document_id, COUNT(id)
FROM documentEntity
GROUP BY parent_document_id;

insert:
INSERT INTO folderEntity(id, parent_id, user_id, title, created_at, last_updated_at, favorite, icon, icon_tint, last_synced_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO
UPDATE SET id=excluded.id, parent_id=excluded.parent_id, user_id=excluded.user_id, title=excluded.title,
 created_at=excluded.created_at, last_updated_at=excluded.last_updated_at, favorite=excluded.favorite,
  icon=excluded.icon, icon_tint=excluded.icon_tint, last_synced_at=excluded.last_synced_at;

-- update:
-- UPDATE(title, parent_id, update_at): SET title=title, parent_id=parent_id, update_at=update_at;

deleteFolder:
DELETE FROM folderEntity WHERE id = ?;

deleteFolderByParent:
DELETE FROM folderEntity WHERE parent_id = ?;

moveToFolder:
UPDATE folderEntity SET parent_id = ?, last_updated_at = ? WHERE id = ?;

setLastUpdate:
UPDATE folderEntity SET last_updated_at = ? WHERE id = ?;

favoriteById:
UPDATE folderEntity SET favorite = ? WHERE id = ?;
