Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
spences10 avatar

Database Patterns

  • 2 installs
  • 6 repo stars
  • Updated August 3, 2026
  • spences10/devhub-crm

Provides SQLite CRUD patterns with better-sqlite3 using prepared statements, nanoid IDs, epoch timestamps, and user-scoped row-level security.

About

Documents SQLite database patterns for the devhub-crm app using better-sqlite3 with prepared statements and user_id-scoped queries. A developer uses it when implementing CRUD operations with row-level security.

  • Prepared statements for all queries and nanoid() for primary keys
  • Always includes user_id in WHERE clauses for row-level security

Database Patterns by the numbers

  • 2 all-time installs (skills.sh)
  • Ranked #743 of 911 Databases skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/spences10/devhub-crm --skill database-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs2
repo stars6
Last updatedAugust 3, 2026
Repositoryspences10/devhub-crm

What it does

Provides SQLite CRUD patterns with better-sqlite3 using prepared statements, nanoid IDs, epoch timestamps, and user-scoped row-level security.

Files

SKILL.mdMarkdownGitHub ↗

Database Patterns

Quick Start

import { db } from '$lib/server/db';
import { nanoid } from 'nanoid';

// SELECT with user_id (row-level security)
const contact = db
	.prepare('SELECT * FROM contacts WHERE id = ? AND user_id = ?')
	.get(id, user_id) as Contact | undefined;

// INSERT with nanoid and timestamps
const stmt = db.prepare(
	'INSERT INTO contacts (id, user_id, name, created_at, updated_at) VALUES (?, ?, ?, ?, ?)',
);
stmt.run(nanoid(), user_id, name, Date.now(), Date.now());

Core Principles

  • Prepared statements: Use for all queries (SQL injection

prevention)

  • ID generation: Use nanoid() for all primary keys (no

auto-increment)

  • Timestamps: Store as Unix epoch with Date.now() (milliseconds)
  • Row-level security: Always include user_id in WHERE clause

(never query by ID alone)

  • Transactions: Use for multi-table operations (all-or-nothing)
  • Synchronous: better-sqlite3 is sync - no async/await needed

Reference Files

  • schema.md - Complete schema with columns and

types

  • relationships.md - Table

relationships and foreign keys

  • query-examples.md - Joins,

transactions, and advanced patterns

Related skills

Databasesdatabases

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.