home / docs / sections

sections: plugin_hooks:the-resources-sql-method

This data as json

id page ref title content breadcrumbs references
plugin_hooks:the-resources-sql-method plugin_hooks the-resources-sql-method The The resources_sql() classmethod returns a SQL query that lists all resources of that type that exist in the system. This query is used by Datasette to efficiently check permissions across multiple resources at once. When a user requests a list of resources (like tables, documents, or other entities), Datasette uses this SQL to: Get all resources of this type from your data catalog Combine it with permission rules from the permission_resources_sql hook Use SQL joins and filtering to determine which resources the actor can access Return only the permitted resources The SQL query must return exactly two columns: parent - The parent identifier (e.g., database name, collection name), or NULL for top-level resources child - The child identifier (e.g., table name, document ID), or NULL for parent-only resources For example, if you're building a document management plugin with collections and documents stored in a documents table, your resources_sql() might look like: @classmethod def resources_sql(cls) -> str: return """ SELECT collection_name AS parent, document_id AS child FROM documents """ This tells Datasette "here's how to find all documents in the system - look in the documents table and get the collection name and document ID for each one." The permission system then uses this query along with rules from plugins to determine which documents each user can access, all efficiently in SQL rather than loading everything into Python. ["Plugin hooks", "register_actions(datasette)"] []
Powered by Datasette · Queries took 3.624ms