database-patterns

Solid

DB schema design and query tuning: normalization, indexing, N+1, transactions, EXPLAIN. Triggers: schema, index, slow query, N+1, PostgreSQL, MySQL, EXPLAIN, deadlock, query plan.

API & Backend 155 stars 19 forks Updated 2 days ago MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
73
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Database Patterns Skill ## ORM Selection | Scenario | ORM | |----------|-----| | Node.js, type-safe | Prisma | | Node.js, SQL-first | Drizzle | | Python, async | SQLAlchemy 2.0 | | Python, simple | SQLModel | | PHP | Doctrine, Eloquent | --- ## Schema Design ### Naming Conventions ```sql -- Tables: plural, snake_case CREATE TABLE user_profiles (...); -- Columns: snake_case user_id, created_at, is_active -- Indexes: idx_{table}_{columns} CREATE INDEX idx_users_email ON users(email); -- Foreign keys: fk_{table}_{ref_table} CONSTRAINT fk_orders_users FOREIGN KEY (user_id) REFERENCES users(id) ``` ### Common Patterns #### Soft Delete ```sql ALTER TABLE users ADD COLUMN deleted_at TIMESTAMP NULL; -- Query active records SELECT * FROM users WHERE deleted_at IS NULL; ``` #### Audit Columns ```sql created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, created_by UUID REFERENCES users(id), updated_by UUID REFERENCES users(id) ``` #### UUID vs Serial | Use Case | Type | |----------|------| | Internal only | SERIAL/BIGSERIAL | | External/distributed | UUID | | Human readable | SERIAL with prefix | --- ## Index Strategies ### When to Index - Foreign keys (always) - Columns in WHERE clauses - Columns in ORDER BY - Columns in JOIN conditions ### Index Types | Type | Use Case | |------|----------| | B-tree | Equality, range (default) | | Hash | Equality only | | GIN | Arrays, JSONB, full-text | | GiST |...

Details

Author
softspark
Repository
softspark/ai-toolkit
Created
2 months ago
Last Updated
2 days ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category