pub(crate) mod sql {
pub(crate) const INSERT_NEW: &str = r#"INSERT OR IGNORE INTO arcature_api_tokens
(id, secret_digest, tokenable_id, name, abilities, expires_at, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?)"#;
pub(crate) const FIND: &str = r#"SELECT tokenable_id, name, abilities, expires_at, created_at
FROM arcature_api_tokens
WHERE id = ?
AND expires_at > CAST((julianday('now')-2440587.5)*86400000 AS INTEGER)"#;
pub(crate) const AUTHENTICATE: &str = r#"SELECT secret_digest, tokenable_id, name, abilities, expires_at, created_at
FROM arcature_api_tokens
WHERE id = ?
AND expires_at > CAST((julianday('now')-2440587.5)*86400000 AS INTEGER)"#;
pub(crate) const LIST_FOR: &str = r#"SELECT id, tokenable_id, name, abilities, expires_at, created_at
FROM arcature_api_tokens
WHERE tokenable_id = ?
AND expires_at > CAST((julianday('now')-2440587.5)*86400000 AS INTEGER)
ORDER BY created_at DESC, id"#;
pub(crate) const DELETE: &str = "DELETE FROM arcature_api_tokens WHERE id = ?";
pub(crate) const DELETE_FOR: &str = "DELETE FROM arcature_api_tokens WHERE tokenable_id = ?";
pub(crate) const DELETE_EXPIRED: &str = r#"DELETE FROM arcature_api_tokens
WHERE expires_at <= CAST((julianday('now')-2440587.5)*86400000 AS INTEGER)"#;
pub(crate) const CREATE_HISTORY: &str = r#"CREATE TABLE IF NOT EXISTS arcature_api_tokens_schema_migrations (
version TEXT PRIMARY KEY,
applied_at INTEGER NOT NULL
DEFAULT (CAST((julianday('now')-2440587.5)*86400000 AS INTEGER))
)"#;
pub(crate) const COUNT_APPLIED: &str =
"SELECT COUNT(*) FROM arcature_api_tokens_schema_migrations WHERE version = ?";
pub(crate) const RECORD_APPLIED: &str =
"INSERT OR IGNORE INTO arcature_api_tokens_schema_migrations (version) VALUES (?)";
pub(crate) const LOCK: Option<&str> = None;
pub(crate) const UNLOCK: Option<&str> = None;
pub(crate) const SCHEMA: &str = include_str!("../migrations/sqlite/0001_api_tokens.sql");
}