Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu7.6k · #13185

storing-data

Skill này làm gì

Skill này giải thích rằng ứng dụng Agent-Native giữ các bản ghi trong SQL, còn các file lớn như ảnh và video đi đến bộ nhớ file. Skill dành cho lập trình viên thêm mô hình dữ liệu hoặc đọc và ghi dữ liệu ứng dụng.

Khi nào nên dùng

  • ✓Khi bạn thêm một mô hình dữ liệu hoặc bảng mới cho ứng dụng.
  • ✓Khi bạn cần quyết định dữ liệu nên nằm trong cơ sở dữ liệu hay trong file.
  • ✓Khi ứng dụng cần lưu một ảnh, video hoặc PDF.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/storing-data/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/storing-data/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm cách lưu ảnh do người dùng tải lên, và giữ bản ghi của từng ảnh trong cơ sở dữ liệu.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bản ghi và tham chiếu được lưu trong cơ sở dữ liệu, còn nội dung nhị phân đi qua các công cụ bộ nhớ file. Chỉ ID hoặc URL trả về được lưu trong cơ sở dữ liệu.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Storing Data — SQL is the Source of Truth

Rule

All application data lives in SQL (local PGlite, hosted Postgres in production). The agent and UI share the same database. SQL stores structured records, metadata, references, and searchable text — not large raw file payloads. Do not store durable app data in the filesystem unless the app is explicitly running a Local File Mode artifact flow described below.

Large binary or file-like payloads (images, video/audio, PDFs, ZIPs, screenshots, session replay chunks, thumbnails, generated assets, data: URLs, and base64 file bodies) must go through configured file/blob storage such as uploadFile() or putPrivateBlob(). Persist only the returned URL, asset id, or opaque blob handle in SQL. If storage is unavailable in hosted or persistent-database mode, fail closed with setup guidance instead of falling back to base64 in application_state, settings, resources, or app tables.

Uploaded files an action opens later (chat attachments, import controls, chunked commits) are one core AttachmentRef: mint with mintAttachmentRef, open with resolveAttachment and unwrapAttachment from @agent-native/core/private-blob. Never write a template descriptor, never branch on error text, and never truncate a ref (ATTACHMENT_REF_MAX_CHARS is the floor for any prompt or field that carries one). Each failure is typed: notFound, forbiddenScope, expired and malformed are definitive and stop the turn, except a value that is not a ref at all or is missing (malformed with unrecognized_scheme or empty), which is an ordinary action error the model corrects by passing the listed ref; only storageUnavailable is retryable, and the same ref works once storage is back, so never ask the user to attach the file again for it.

Local File Mode exception: some artifact apps (Content, Plans, Slides, Dashboards, Designs, etc.) can intentionally use repo files as the source of truth for the artifact itself. This must be explicit via agent-native.json, AGENT_NATIVE_MODE=local-files, or an app-owned local-file action helper. In that mode, the UI and agent still go through app actions, but those actions read/write scoped files through @agent-native/core/local-artifacts instead of SQL rows. App state, auth, settings, credentials, collaboration metadata, and hosted database mode remain SQL. File-to-database or file-to-provider synchronization is an explicit sync step, not an implicit side effect of editing.

When you add a data model, a list, or a read path, also follow the performance skill: project only the columns a list renders, index the columns hot queries filter/sort on, and avoid query waterfalls — so apps stay fast as data grows.

How It Works

Agent-Native apps use Drizzle ORM over PostgreSQL. Local development uses PGlite at data/pglite; production and shared preview deploys need a persistent hosted PostgreSQL DATABASE_URL.

For app code, use Drizzle's schema/query DSL by default. Raw SQL is an escape hatch for additive migrations, health checks, or one-off maintenance, not the normal way to build features.

Typed raw SQL fragments

When Drizzle cannot express a PostgreSQL query, import sql from @agent-native/core/db and pass its fragment directly to getDbExec().execute(). Use sql.value(value) for bound values, sql.ident(name) for validated lowercase identifiers, sql.in(values) for a nonempty list (it includes parentheses), and sql.join(fragments, separator) or nested fragments for composition. The tag rejects plain string interpolation at compile time; do not build { sql: ...${value}... } or pass interpolated templates directly to execute(). The diff-scoped guard checks new interpolated SQL reaching getDbExec().execute() through the helper and wrapper paths it analyzes. A reviewed exception needs // raw-sql-ok: <reason> as a standalone comment immediately before the sink statement or after it on the same line. Markers inside SQL text, callbacks, and object properties do not opt out. The guard does not audit Drizzle sql.raw() or raw adapter query() calls, so use bound Drizzle fragments or the typed kernel instead of interpolating dynamic values through those APIs.

Schema and migration ownership

Define PostgreSQL tables with Drizzle's drizzle-orm/pg-core exports and use drizzle-orm for query operators. Import only framework-owned sharing helpers, such as ownableColumns() and createSharesTable(), fro

Câu hỏi thường gặp

Dữ liệu ứng dụng có thể lưu thành file trên đĩa không?

Thường là không. Dữ liệu ứng dụng bền vững không nên nằm trong hệ thống file trừ khi dùng một chế độ file cụ thể.

Tôi có nên lưu ảnh dưới dạng văn bản base64 trong cơ sở dữ liệu không?

Không. Skill nói nên báo lỗi kèm hướng dẫn thiết lập thay vì lưu nội dung file vào cơ sở dữ liệu.

Tôi lưu gì trong cơ sở dữ liệu cho một file?

Chỉ URL, ID tài sản hoặc handle không rõ nghĩa của nó.

Chi tiết

Mô tả gốc của tác giả

How to store application data in agent-native apps. All data lives in SQL. Use when adding data models, deciding where to store data, or reading/writing application data.

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13185
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự