Module sql_constants

Module sql_constants 

Source
Expand description

SQL query constants and fragments

This module centralizes frequently-used SQL query strings and fragments to:

  1. Reduce code duplication
  2. Ensure consistency across the codebase
  3. Make query modifications easier to maintain

§Design Philosophy

  • Column Lists: Reusable SELECT column specifications
  • Base Queries: Complete SELECT statements with standard FROM clauses
  • Existence Checks: Common existence validation patterns

Note: Dynamic WHERE clauses are still built inline for flexibility.

Constants§

CHECK_TASK_EXISTS
Check if a task exists by ID
CHECK_TASK_EXISTS_FOR_EVENT
Check if a task exists (also used by event validation)
COUNT_CHILDREN_TOTAL
Count total children of a parent
COUNT_EVENTS_FOR_TASK
Count events for a specific task
COUNT_EVENTS_TOTAL
Count total events
COUNT_INCOMPLETE_CHILDREN
Count incomplete subtasks of a parent
COUNT_INCOMPLETE_CHILDREN_EXCLUDE
Count incomplete children excluding specific task
COUNT_INCOMPLETE_TASKS_EXCLUDE
Count incomplete tasks excluding specific task
COUNT_TASKS_DOING
Count tasks with ‘doing’ status
COUNT_TASKS_FTS
Count task FTS5 matches
COUNT_TASKS_INCOMPLETE
Count incomplete tasks (todo or doing)
COUNT_TASKS_TOTAL
Count total tasks
EVENT_COLUMNS
Standard column list for event queries
SELECT_EVENT_BASE
Base SELECT query for events with dynamic WHERE clause building
SELECT_EVENT_BY_ID
SELECT event with WHERE id = ? condition
SELECT_EVENT_FULL
Base SELECT query for events
SELECT_TASKS_FTS_BASE
Base query for task FTS5 search
SELECT_TASK_FULL
Base SELECT query for tasks (with spec)
SELECT_TASK_NAME
Get task name by ID
SELECT_TASK_NAME_PARENT
Get task name and parent_id by ID
SELECT_TASK_NO_SPEC
Base SELECT query for tasks (without spec, using NULL)
SELECT_TASK_PARENT_ID
Get parent_id for a task
TASK_COLUMNS
Standard column list for task queries (includes spec column)
TASK_COLUMNS_NO_SPEC
Task column list without spec (uses NULL placeholder)