database-skill
Sets up and manages TinyDB instances, handling configuration, CRUD operations, and ID generation.
Install
mkdir -p .claude/skills/database-skill && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/17204" && unzip -o skill.zip -d .claude/skills/database-skill && rm skill.zipInstalls to .claude/skills/database-skill
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Configure and operate TinyDB for JSON-based document storage. Use when setting up databases, creating queries, or managing data persistence.Key capabilities
- →Set up TinyDB with caching middleware for JSON storage.
- →Generate unique IDs for new database entries.
- →Perform create, read, update, and delete operations on tasks.
- →Search database entries using various query patterns.
- →Manage database connections by opening and closing them.
How it works
The skill initializes a TinyDB instance with caching and a specified JSON file path, then defines methods for common database operations like inserting, retrieving, updating, and deleting records.
Inputs & outputs
When to use database-skill
- →Setting up local database persistence
- →Managing task storage in JSON
- →Implementing CRUD operations
- →Configuring database caching
About this skill
Database Skill
Purpose
Set up and manage TinyDB document database with proper configuration and query patterns.
Instructions
Database Setup
from tinydb import TinyDB, Query
from tinydb.storages import JSONStorage
from tinydb.middlewares import CachingMiddleware
from pathlib import Path
from typing import Optional, List
class TodoDatabase:
"""TinyDB wrapper for todo task storage."""
def __init__(self, db_path: str = "todo_data.json"):
"""Initialize database with caching."""
self.db_path = Path(db_path)
self.db = TinyDB(
self.db_path,
storage=CachingMiddleware(JSONStorage),
indent=2,
ensure_ascii=False
)
self.tasks = self.db.table('tasks')
self.query = Query()
def close(self):
"""Close database connection."""
self.db.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.close()
ID Generation
def get_next_id(self) -> int:
"""Generate next unique ID."""
all_tasks = self.tasks.all()
if not all_tasks:
return 1
return max(task['id'] for task in all_tasks) + 1
CRUD Operations
def insert(self, task: dict) -> int:
"""Insert a new task."""
task['id'] = self.get_next_id()
doc_id = self.tasks.insert(task)
return task['id']
def get(self, task_id: int) -> Optional[dict]:
"""Get task by ID."""
return self.tasks.get(self.query.id == task_id)
def get_all(self) -> List[dict]:
"""Get all tasks."""
return self.tasks.all()
def update(self, task_id: int, updates: dict) -> bool:
"""Update task by ID."""
result = self.tasks.update(updates, self.query.id == task_id)
return len(result) > 0
def delete(self, task_id: int) -> bool:
"""Delete task by ID."""
result = self.tasks.remove(self.query.id == task_id)
return len(result) > 0
Query Patterns
# Simple equality
tasks = db.tasks.search(db.query.priority == 'high')
# Logical AND
tasks = db.tasks.search(
(db.query.priority == 'high') &
(db.query.status == 'pending')
)
# Logical OR
tasks = db.tasks.search(
(db.query.priority == 'high') |
(db.query.priority == 'urgent')
)
# NOT
tasks = db.tasks.search(~(db.query.status == 'completed'))
# Test function (for complex conditions)
tasks = db.tasks.search(
db.query.title.test(lambda t: 'keyword' in t.lower())
)
# Check if value in list
tasks = db.tasks.search(
db.query.tags.test(lambda tags: 'work' in tags)
)
# Exists check
tasks = db.tasks.search(db.query.due_date.exists())
# Comparison operators
tasks = db.tasks.search(db.query.priority != 'low')
Full Database Class
class TodoDatabase:
def __init__(self, db_path: str = "todo_data.json"):
self.db = TinyDB(
db_path,
storage=CachingMiddleware(JSONStorage),
indent=2
)
self.tasks = self.db.table('tasks')
self.query = Query()
def get_next_id(self) -> int:
all_tasks = self.tasks.all()
return max((t['id'] for t in all_tasks), default=0) + 1
def insert(self, task: dict) -> int:
task['id'] = self.get_next_id()
self.tasks.insert(task)
return task['id']
def get(self, task_id: int) -> Optional[dict]:
return self.tasks.get(self.query.id == task_id)
def get_all(self) -> List[dict]:
return self.tasks.all()
def search(self, condition) -> List[dict]:
return self.tasks.search(condition)
def update(self, task_id: int, updates: dict) -> bool:
return bool(self.tasks.update(updates, self.query.id == task_id))
def delete(self, task_id: int) -> bool:
return bool(self.tasks.remove(self.query.id == task_id))
def clear(self):
self.tasks.truncate()
def close(self):
self.db.close()
Best Practices
- Use CachingMiddleware for better performance
- Always handle database closing properly
- Use context managers for automatic cleanup
- Generate IDs automatically
- Use Query objects for type-safe queries
- Index frequently queried fields conceptually
When not to use it
- →When a relational database is required.
- →When data persistence is not needed.
- →When a non-JSON document storage is preferred.
Limitations
- →The database is file-based and local.
- →Queries are performed using TinyDB's Query object syntax.
- →Data is stored in JSON format.
How it compares
This skill provides a structured Python class for TinyDB operations, abstracting direct database interactions into reusable methods, unlike manual file-based JSON management.
Compared to similar skills
database-skill side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| database-skill (this skill) | 0 | 8mo | No flags | Beginner |
| senior-data-engineer | 21 | 8mo | Review | Advanced |
| hugging-face-datasets | 1 | 7mo | Review | Intermediate |
| extract-test-set | 1 | 6mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by maneeshanif
View all by maneeshanif →You might also like
senior-data-engineer
davila7
World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, and data infrastructure. Expertise in Python, SQL, Spark, Airflow, dbt, Kafka, and modern data stack. Includes data modeling, pipeline orchestration, data quality, and DataOps. Use when designing data architectures, building data pipelines, optimizing data workflows, or implementing data governance.
hugging-face-datasets
patchy631
Create and manage datasets on Hugging Face Hub. Supports initializing repos, defining configs/system prompts, streaming row updates, and SQL-based dataset querying/transformation. Designed to work alongside HF MCP server for comprehensive dataset workflows.
extract-test-set
tradingstrategy-ai
Extract raw price dataframe for a test case
bsl-model-builder
boringdata
Build BSL semantic models with dimensions, measures, joins, and YAML config. Use for creating/modifying data models.
data-quality-frameworks
Anhvu1107
ALWAYS use this when the request matches Data Quality Frameworks: Implement data quality validation with Great Expectations, dbt tests, and data contracts.
df-basic-stats
qmakescl
>