storing-data
できること
このスキルは、Agent-Native アプリが記録を SQL に保存する一方で、画像、動画、PDF などの大きなファイルはファイル保存領域に送ることを説明します。データモデルを追加したり、アプリのデータを読み書きしたりする開発者向けです。
使う場面
- ✓アプリに新しいデータモデルやテーブルを追加するとき。
- ✓データをデータベースに保存すべきか、ファイルにすべきか決める必要があるとき。
- ✓アプリが画像、動画、PDF を保存する必要があるとき。
スキルのリンク
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/storing-data/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“利用者がアップロードした画像を保存できるようにしてください。各画像の記録はデータベースに残してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
記録と参照はデータベースに保存されます。バイナリの内容はファイル保存の仕組みを通します。データベースには、返された ID や URL だけを保存します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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
よくある質問
アプリのデータをディスク上のファイルとして保存してよいですか?
通常は避けるべきです。特定のファイルモードを使う場合を除き、永続的なアプリのデータはファイルシステムに置かないでください。
画像を base64 のテキストとしてデータベースに保存してもよいですか?
いいえ。スキルは、ファイルの内容をデータベースに保存する代わりに、設定の案内と共に失敗させるよう述べています。
ファイルについて、データベースに何を保存しますか?
URL、ファイル ID、不透明なハンドルのいずれかだけです。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 7.6k
- ランキング
- #13185
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
design-exploration
7.6kUIの複数のデザインの方向性を並べて検討し、1つを選んでもらい、選んだデザインを磨き上げるようエージェントを支援します。
visual-edit
7.6k実行中のローカルのアプリをビジュアルエディターで開き、本物の画面をまとめて確認し編集できるようエージェントを支援します。
turn-into-app
7.6kワークフロー、スプレッドシート、プロジェクトを、画面にデータが入り、操作の裏でエージェントが働く、洗練されたビジュアルアプリに変えます。
visual-plan
7.6kプレーンテキストの計画を、図、ファイルのマップ、コードの断片、未解決の質問を含む、対話できるビジュアルな計画に変えます。
似ているスキル
discrawl
394k保存済みのローカルなDiscordメッセージのアーカイブを検索して要約し、その新しさを確認し、ダイレクトメッセージを読めるようエージェントを支援します。
clickhouse-io
280kエージェントがClickHouseデータベースのクエリとスキーマを最適化できるようにします。高性能な分析処理向けのベストプラクティスを適用します。分析クエリが遅すぎるときに使います。
scientific-db-pubmed-database
280kエージェントが生物医学分野の科学論文を検索するのに役立ちます。特定の医療情報が必要な研究に便利です。