Pular para o conteúdo
Skillpedia
APIs e servidores (backend)25 mil · #10083

nocobase-db

O que ela faz

Esta skill orienta sua IA na camada de banco de dados de um app NocoBase 3. Ela é indicada para desenvolvedores que adicionam tabelas, migrações ou lógica de dados a um app.

Quando usar

  • ✓Quando você precisa adicionar ou alterar uma tabela ou campo em um app NocoBase 3.
  • ✓Quando você escreve código que lê ou salva registros e precisa de transações.
  • ✓Quando você configura uma conexão com o banco de dados ou escreve uma migração ou seed.

Link da skill

https://github.com/nocobase/nocobase/blob/v3-develop/packages/libs/db/skills/nocobase-db/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/nocobase/nocobase/blob/v3-develop/packages/libs/db/skills/nocobase-db/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Você pode adicionar uma tabela de pedidos ligada a clientes no meu app NocoBase, usando uma migração?”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A IA escolhe a camada certa para a tarefa: configuração, migrações, o construtor de esquema ou o repositório de tempo de execução. Em seguida, escreve o código com a API correta e o tratamento adequado de transações.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

The database in a NocoBase 3 application

Most mistakes here are made before the first line of code, by putting a task at the wrong layer: changing schema from runtime code, reading records through the schema builder, or reimplementing relation writes on top of raw queries.

Six areas, in the order an application grows into them:

Area Owns
Configuration which databases exist, and which dialect each one speaks
Migrations and seeds schema history and install data
Builder how a migration declares tables, fields and constraints
Repository and Query runtime reads and writes
Transactions making several writes succeed or fail together
Collections what the database actually resolves to, for code and for you

The exact parameters and return types are always the TypeScript declarations in @nocobase/db. This Skill decides which API to reach for, where the code belongs, and the boundaries the types cannot express.

Where the code lives

server/config/database.ts          connections and the default connection
config.yml                         per-environment overrides and credentials (gitignored)
database/<connection>/migrations   schema history for that connection
database/<connection>/seeds        install data for that connection
database/<connection>/collections  resolved Collection artifacts
server/routes/, server/providers   runtime reads and writes

<connection> is a connection name from server/config/database.ts, so the default connection's migrations are in database/main/migrations/. Adding a connection means adding its directory alongside and keeping database/tsconfig.json in place, so migrations and seeds are typechecked and linted as server source.

Runtime code never changes schema, and a migration never imports runtime code. That split is what these directories encode.

1. Configuration

Connections are declared in code and overridden per environment:

Location Responsibility
server/config/database.ts Connection defaults through defineAppDatabaseConfig
config.yml Environment overrides including credentials — gitignored
config.example.yml The documented structure and credential placeholders; keep it in step
import {
  connectionEnvironment,
  defineAppDatabaseConfig,
} from '@nocobase/app-server/database';

export default defineAppDatabaseConfig(
  ({ paths }) => ({
    default: 'main',
    connections: {
      main: {
        dialect: 'sqlite',
        filename: paths.storage('database.sqlite'),
        schemaManagement: 'managed',
        debug: false,
      },
    },
  }),
  { env: connectionEnvironment('main') },
);

The second argument maps environment variables onto the section: connectionEnvironment('main') declares DB_DIALECT, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_SSL and DB_FILENAME for the main connection, each overriding config.yml. Only main has them; a connection you add declares its own with a prefix naming it, connectionEnvironment('analytics', 'DB_ANALYTICS'), merged into the same env.

The dialects are sqlite, postgres, mysql, mssql, oracle, dameng, kingbase and oceanbase. Each is an optional peer of @nocobase/app-server shipped as its own package: install @nocobase/db-<dialect> into dependencies — so it reaches the deployed server — and configure the dialect. No import or driver registration is needed, and the dialect package brings its own underlying driver.

Switching a dialect means changing both layers. config.yml deep-merges into the code defaults, so editing only the code leaves a stale YAML override in place — with fields belonging to the previous dialect still applied. Remove filename

Perguntas frequentes

Posso alterar tabelas a partir do código de tempo de execução comum?

A skill diz que alterações de tabela pertencem às migrações, e não ao código de tempo de execução.

Isto serve para o NocoBase 2?

Não. O NocoBase 2 usa um pacote de banco de dados diferente.

O que é um seed?

Um seed preenche o banco de dados com dados iniciais de instalação de que o app precisa para iniciar.

Detalhes

Descrição original do autor

Work with the database in a NocoBase 3 application: configure connections and dialects, add migrations and seeds, declare schema with the Collection Builder, read and write records with Repository or QueryAdapter, run transactions, and read Collection definitions. Use for any task under database/ or any server code that touches data. Do not use for the NocoBase 2 @nocobase/database package.

repo: nocobase/nocobase

Popularidade

Estrelas no GitHub
25 mil
Posição no ranking
#10083
Licença
—
Atualizada em
02/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas