frappe-core-database

Guide Frappe database operations using ORM, Query Builder, and parameterized SQL.

163|53|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-core-database-impertio-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: frappe-core-database
Source: https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package/tree/main/skills/source/core/frappe-core-database
Command: npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-core-database-impertio-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents production-breaking Frappe database mistakes by guiding Claude to use the right ORM/database APIs, safe query patterns, and correct transaction behavior for ERPNext/Frappe v14–v16.

Core Features & Use Cases

  • Choose the right data access layer: Use frappe.get_doc and frappe.db.get_value for reads, frappe.db.get_list for permission-aware lists, and frappe.delete_doc/frappe.db.delete for safe deletion paths.
  • Prevent SQL injection and query bugs: Enforce parameterized SQL for frappe.db.sql and prefer frappe.qb for complex queries that need joins/aggregation.
  • Avoid common anti-patterns: Stop the top issues like committing inside hooks, using get_doc in existence checks, missing tab prefixes, doing SELECT * and forgetting pagination, and running N+1 queries.
  • Use v14–v16 compatible performance patterns: Apply caching correctly (frappe.get_cached_doc, frappe.db.get_value cache=True, Redis cache guidance) and use transaction hooks where available (v15+).

Quick Start

Ask Claude: "Generate Frappe v16 code to read a Sales Invoice by name, return only specific fields with permission-aware listing when needed, and include safe parameterized SQL or the Query Builder where appropriate."

Frequently Asked Questions about frappe-core-database

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent SQL injection when using frappe.db.sql in ERPNext?

Prevent SQL injection in Frappe by using parameterized SQL with frappe.db.sql and passing variables as a parameter list. For complex queries needing joins or aggregations, prefer the frappe.qb Query Builder to avoid unsafe string interpolation.

What is the difference between frappe.db.get_list and frappe.get_all for database operations?

frappe.db.get_list enforces permission-aware listing for database operations, ensuring users only see records they can access. In contrast, frappe.get_all bypasses permission checks, making get_list the correct choice for secure Frappe CRUD workflows.

How do I avoid N+1 queries and improve performance in Frappe ORM?

Avoid N+1 queries in the Frappe ORM by using frappe.db.get_list or frappe.qb to fetch related records in batched queries. Apply pagination, use specific field selection instead of SELECT *, and leverage frappe.get_cached_doc for repeated single-record reads.

Does Frappe Query Builder support joins and aggregations for v14 to v16?

Yes, the Frappe Query Builder supports joins and aggregations across v14 to v16. Using frappe.qb for complex query logic is the recommended pattern to safely build structured queries without writing raw SQL.

Why should I use the tab prefix for table names in Frappe raw SQL queries?

You must use the tab prefix for table names in Frappe raw SQL queries because the framework prefixes all DocType tables with 'tab' in the database. Omitting it causes query failures since the database cannot find the correct table name.

When should I use frappe.get_cached_doc instead of frappe.get_doc?

Use frappe.get_cached_doc instead of frappe.get_doc when you need to read the same document multiple times within a request, as it retrieves the document from Redis cache. This avoids repeated database queries and significantly improves application performance.