ZestyDB

SQL Commands within Functionalities (async function)

You can find our worker code here. The functions are located at the bottom of the file.

getTasks(view, categoryId, selectedDate, env)

Default View

SELECT 
  * 
FROM 
  tasks 
WHERE 
  DATE(due_date) <= ? 
  AND status = 'active' 
ORDER BY 
  priority_level IS NULL, 
  priority_level

Category View

SELECT 
  * 
FROM 
  tasks 
WHERE 
  category_id = ? 
ORDER BY 
  priority_level IS NULL, 
  priority_level, 
  due_date

Completed View

SELECT 
  * 
FROM 
  tasks 
WHERE 
  status = 'completed' 
  AND DATE(due_date) = ? 
ORDER BY 
  due_date

Everything View

SELECT 
  * 
FROM 
  tasks 
ORDER BY 
  due_date, 
  priority_level

getAllCategories(env)

SELECT 
  * 
FROM 
  categories 
ORDER BY 
  name

addTask(formData, env)

INSERT INTO tasks (
  description, due_date, category_id, 
  priority_level, status
) 
VALUES 
  (?, ?, ?, ?, ?)

addCategory(formData, env)

INSERT INTO categories (name) 
VALUES 
  (?)

deleteTask(id, env)

DELETE FROM 
  tasks 
WHERE 
  id = ?

updateTask(id, formData, env)

UPDATE 
  tasks 
SET 
  description = ?, 
  due_date = ?, 
  category_id = ?, 
  priority_level = ?, 
  status = ? 
WHERE 
  id = ?

updateCategory(id, formData, env)

UPDATE 
  categories 
SET 
  name = ? 
WHERE 
  id = ?

resetCategory(id, env)

UPDATE 
  tasks 
SET 
  category_id = NULL 
WHERE 
  category_id = ?

deleteCategory(id, env)

  1. First: all of the tasks associated with this Category are deleted from their Tasks table.
  2. Second: We delete the category from its table.
DELETE FROM 
  tasks 
WHERE 
  category_id = ? 

DELETE FROM 
  categories 
WHERE 
  id = ?