AgentSkillsCN

syntra-db

利用 Syntra 进行数据库管理。适用于创建表、定义数据结构、查询记录、插入数据、执行 SQL,或管理数据库架构时使用。涵盖 CRUD 操作、数据结构设计、迁移、筛选,以及 PostgreSQL 函数。

SKILL.md
--- frontmatter
name: syntra-db
description: Database management with Syntra. Use when creating tables, defining schemas, querying records, inserting data, running SQL, or managing database structure. Covers CRUD operations, schema design, migrations, filtering, and PostgreSQL functions.

Syntra Database

Schema design workflow

  1. database_list_tables — see existing tables
  2. database_create_table — create with typed columns
  3. database_get_table_schema — verify the result
  4. database_alter_table — modify later (add/drop/rename columns)

Create table example

json
{
  "table_name": "posts",
  "columns": [
    { "name": "id", "type": "uuid", "is_primary_key": true, "default_value": "gen_random_uuid()" },
    { "name": "title", "type": "text", "nullable": false },
    { "name": "body", "type": "text" },
    { "name": "author_id", "type": "uuid", "nullable": false },
    { "name": "published", "type": "boolean", "default_value": "false" },
    { "name": "created_at", "type": "timestamptz", "default_value": "now()" }
  ]
}

CRUD operations

  • Insert: database_insert_records with records array and optional returning
  • Select: database_select_records with filters, order, limit, offset
  • Update: database_update_records with data and filters
  • Delete: database_delete_records with filters
  • Upsert: database_bulk_upsert with conflict_columns

Filters (PostgREST syntax)

Filters use {"column": "operator.value"} format:

OperatorMeaningExample
eqEquals{"status": "eq.active"}
neqNot equals{"role": "neq.admin"}
gt / gteGreater than{"age": "gte.18"}
lt / lteLess than{"price": "lt.100"}
likePattern match{"name": "like.%john%"}
ilikeCase-insensitive pattern{"email": "ilike.%@gmail.com"}
isIS NULL / IS NOT NULL{"deleted_at": "is.null"}
inIn list{"status": "in.(active,pending)"}

Order: "created_at.desc" or "name.asc"

Raw SQL

  • database_execute_sql — read-only (SELECT, WITH, EXPLAIN)
  • database_execute_sql_write — any statement (INSERT, UPDATE, CREATE, ALTER, DROP)

Use parameterized queries with params: ["$1_value", "$2_value"].

Database metadata

  • database_list_functions — PostgreSQL functions
  • database_list_indexes — table indexes
  • database_list_policies — Row Level Security policies
  • database_list_triggers — table triggers
  • database_execute_rpc — call a PostgreSQL function by name

Column types and query patterns