Communitygithub.com

evalix098/tiktoklive

在此 TanStack Start 應用程式中使用 Neon Postgres(資料庫)。當應用程式需要儲存或查詢資料、持久化狀態或保留每個使用者的資料時使用。觸發關鍵字:「database」、「Postgres」、「Neon」、「save data」、「store data」、「persist」、「tables」、「SQL」、「query」、「migrations」。

tiktoklive 是什麼?

此技能為 TanStack Start 應用程式提供了一個現成的雙模式資料庫整合方案,支援 Neon Postgres(正式環境)和 PGLite(本機預覽環境)。當應用程式需要持久化跨瀏覽器會話或用戶間共享的資料時,會自動觸發此技能。它透過一個統一的 `getSql()` 函式提供相同的 API,無論是在正式環境還是預覽環境中都能運作。此技能也包含了遷移管理、伺服器端查詢執行以及用戶資料隔離的指引,並特別強調了安全性和與 TanStack Start 架構的相容性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/evalix098/tiktoklive/tree/HEAD/.grok/skills/neon

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Neon Postgres

資料庫是選擇性的(AGENTS.md §0.5):僅在應用程式需要儲存比瀏覽器會話更久或可跨裝置共享的資料時使用。否則,不要匯入 @/lib/db,也不要提供遷移檔案,並將狀態保留在 localStorage / zustand 中。

此模板提供了一個現成的雙模式資料庫整合:

  • 已設定(已設定環境變數,例如已部署):使用真正的 Neon Postgres。
  • 未設定(沙盒即時預覽):資料庫會回退到本機的 PGLite(嵌入式 WASM Postgres),因此預覽始終能正常渲染。請使用 @/lib/db 輔助程式進行開發;兩種模式使用相同的 API。

套件已預先安裝 — 請勿再次執行 npm install:pg(node-postgres,標準 Postgres 驅動程式)和 @electric-sql/pglite(本機資料庫回退方案)。

有關使用者帳戶、登入和讀取目前使用者,請參閱單獨的 auth 技能 — 此技能僅涵蓋資料庫部分。

開啟資料庫

在 .grok/app-env.json 中將 deploy.database 設定為 true:

{ "VITE_AUTH_ENABLED": "false", "deploy": { "database": true } }

這會告訴平台為已部署的應用程式佈建 Neon;將其保留為 false,則部署時不會獲得 DATABASE_URL,因此應用程式會在一個用完即棄的 PGLite 上默默運行,其資料行將會遺失。提供 migrations/*.sql 或登入功能時,無論此標誌為何,都會自動佈建 Neon。此標誌適用於在沒有這兩者的情況下查詢 @/lib/db 的應用程式。它不是 VITE_ 金鑰,也永遠不會到達瀏覽器。

環境變數 — 請勿建立 .env 檔案

永遠不要為資料庫編寫 .env / .env.local / .env.example。 在沙盒即時預覽中,請讓 DATABASE_URL 保持未設定 — @/lib/db 會自動使用嵌入式的 PGLite。當應用程式部署後,平台會注入 DATABASE_URL(Neon);您無需自行佈建或編寫它。

變數位置用途
DATABASE_URL伺服器部署時的 Neon 連線字串(可選 — 若未設定則使用 PGLite 回退方案)

切勿對其進行硬編碼;切勿將非 VITE_ 的變數暴露給客戶端。

資料庫(僅限伺服器端)

@/lib/db 匯出了 getSql() 和 dbSource:當 DATABASE_URL 已設定時,使用標準 Postgres 驅動程式(node-postgres,pg);未設定時,則使用本機的 PGLite 回退方案。兩種情況使用相同的 API:一個標記模板(和 .query() 方法),解析為 rows[]。僅能從 createServerFn 處理程式 / 伺服器載入函式中呼叫,絕不能從客戶端元件中呼叫。請在 migrations/ 中定義結構,不要內聯。

import { createServerFn } from "@tanstack/react-start";
import { getSql } from "@/lib/db";

export const listPosts = createServerFn({ method: "GET" }).handler(async () => {
  const sql = await getSql();
  // 為資料行形狀定義型別 — 伺服器函數的回傳值必須是可證明可序列化的。
  return sql<{ id: number; title: string }>`select id, title from posts order by id desc`;
  // 或:return sql.query<{ id: number; title: string }>("select id, title from posts where id = $1", [id]);
});

每個使用者的資料(僅在應用程式有登入功能後)。 標準驅動程式具有完整的資料庫存取權限,因此請在伺服器端將每個查詢都限定於已驗證的使用者 — 切勿信任客戶端發送的 ID。使用預先配置好的 authMiddleware 來取得已驗證的 context.userId,然後根據該 ID 進行過濾。完整模式(中介軟體、從客戶端程式碼呼叫、失敗關閉語義)請參閱 auth 技能:

import { authMiddleware } from "@/lib/auth/middleware";

export const listTodos = createServerFn({ method: "GET" })
  .middleware([authMiddleware])
  .handler(async ({ context }) => {
    const sql = await getSql();
    return sql<{ id: number; title: string }>`select id, title from todos where user_id = ${context.userId} order by id desc`;
  });
// 修改操作也必須限定寫入範圍:`... where id = ${id} and user_id = ${context.userId}`

在沒有登入功能的情況下(預設),請勿使用 authMiddleware / requireUserId。 它們回退到的開發人員使用者僅是預覽用的便利設施。已部署應用程式的 VITE_AUTH_ENABLED 由平台設定,而非此工作區(目前部署器始終將其設為 "true"),因此部署後,兩者都會拒絕所有訪客 — 並且關閉驗證的應用程式沒有提供登入路由供他們恢復。僅使用資料庫的應用程式應將其資料行保留為無所屬狀態:不要有 user_id 欄位,或使用一個固定常數。在啟用登入功能時(auth 技能的升級步驟),再加入中介軟體,屆時再重新設定這些資料行的範圍或將其刪除。

無所屬的資料行可透過您的公開伺服器函數被全世界讀取和寫入:在此模式下,切勿持久化個人或敏感資料(姓名、電子郵件、關於個人的自由文字),並避免使用破壞性的批量修改(全部刪除、全部覆寫)— 如果應用程式需要這些功能,請提議改用登入功能。

遷移

migrations/*.sql 是唯一的結構來源。它們會套用到部署時的 Neon(npm run build 會針對 DATABASE_URL 執行 db:migrate,因此 Vercel 在部署時已準備好結構)和啟動時自動套用到 PGLite 預覽,因此開發環境與正式環境一致。

兩種套用器都不會進入子目錄,因此位於 migrations/auth/0001_auth.sql 的 Better Auth 結構不會被套用,除非應用程式開啟登入功能並將其複製到上層目錄(請勿編輯 — 請參閱 auth 技能)。請將您應用程式的結構放在從 0002 開始編號的新檔案中:

-- migrations/0002_schema.sql — 以待辦事項應用程式為例;請使用您應用程式的資料表
create table if not exists todos (
  id         serial primary key,
  user_id    text not null,
  title      text not null,
  done       boolean not null default false,
  created_at timestamptz not null default now()
);
create index if not exists todos_user_id_idx on todos (user_id);

切勿編輯已套用的檔案 — 它會按名稱記錄在 _migrations 中,並且不會重新執行(請改為新增一個新檔案;新檔案會在下次請求時套用到正在執行的預覽)。建議使用冪等陳述式(… if not exists)。包含每個使用者資料的資料表應有一個 user_id text not null 欄位(TEXT 型別,非 UUID — 預覽的開發人員使用者 ID 是字串 'dev-user')。

預覽 ↔ 正式環境的差異

getSql() 會正規化結果型別,使兩個後端都回傳相同、JSON 安全的形狀:bigint/count(*) → number,date → 'YYYY-MM-DD' 字串,interval → 文字,numeric → 字串。需要注意的其餘差異:

  • 超過 2^53 的 bigint 會損失精確度,因為轉換為數字 — 如果您需要處理超大整數,請將其轉換為 ::text(資料行計數沒問題)。
  • 預覽資料庫是記憶體資料庫:開發伺服器重新啟動時資料會清除、單一連線(無鎖競爭或並發寫入衝突),且不載入任何擴充套件 — 請勿執行 create extension;堅持使用核心 Postgres 功能。
  • Neon 的連線池端點不保留任何工作階段狀態 — 請勿依賴 SET、LISTEN/NOTIFY 或工作階段建議鎖。
  • 將 user_id 欄位保持為 text 型別 — 預覽使用 'dev-user',正式環境使用 Better Auth 的文字 ID;uuid 欄位會破壞預覽的插入。
  • 已部署的 Neon 查詢會經過網路傳輸(並可能經歷冷啟動)— 請避免在程序內預覽資料庫中看起來很輕量的 N+1 查詢模式。

Individual skills in this repo

This repo contains 17 individual skills — each has its own dedicated page.

evalix098/tiktoklive

Add user accounts and sign-in to this TanStack Start app. Use when the app needs authentication, sign-in, user accounts, protected routes, or per-user data. Triggers on "auth", "login", "log in", "sign in", "sign up", "account", "users", "authentication", "protected", "who is logged in", "current user", "per-user".

evalix098/tiktoklive

Build browser games and interactive/canvas/3D experiences in this TanStack Start + React app. Use for any game, simulation, or WebGL/Canvas experience — 2D or 3D, single-player. Covers the game loop & timing, 3D orientation/camera conventions, collision, performance, assets, audio, save, game feel, and per-genre playbooks. For WASD / vehicle / flight **input signs and inverted A/D**, open the **`controls`** skill — do not rely on this file or racing-kart alone. Triggers on "game", "minecraft", "fps", "platformer", "racing", "tetris", "snake", "shooter", "3d", "three.js", "canvas", "voxel", "physics".

evalix098/tiktoklive

Player-facing input signs for browser games: WASD, vehicles, flight, FPS mouse-look, and the #1 failure mode (inverted A/D). Mandatory control self-tests and a tiny test interface so you can verify A turns left before shipping. Load for ANY game with movement, steering, flying, driving, tanks, boats, mechs, drones, planes, karts, third-person follow cams — not only racing. Triggers on "controls", "WASD", "inverted", "steer", "flight", "airplane", "kart", "vehicle", "yaw", "roll", "pitch", "mouse look", "A/D".

evalix098/tiktoklive

Design and build polished, non-generic UI for this TanStack Start + React + Tailwind v4 + shadcn/Radix app. Use whenever you create or restyle any interface surface — pages, landing pages, dashboards, forms, modals, nav, and game overlays (start screens, HUD, menus). Covers design tokens, layout, typography, color, spacing, motion, and the anti-"AI-slop" rules that keep output from looking generic. Triggers on "design", "UI", "make it look good", "polish", "landing page", "theme", "style", "redesign", "ugly", "clean up".

evalix098/tiktoklive

Deep guide for game ANIMATION assets: motion cycles, action keyframes, effect sequences, and animation sprite sheets — built around a video-first pipeline. In this app-builder sandbox, execute via the video2dsprite / generate2dsprite skills (magenta + scripts), not ad-hoc ffmpeg. Use whenever generating anything that moves: walk/run cycles, attacks, idles, FX, flags, fire, animation sheets. Complements game-asset-core.

evalix098/tiktoklive

Core discipline for ANY game-asset generation with Imagine tools: the engine-ready defaults users don't state, spec checklists, style anchoring, read-back verification, honest defect flagging. Use whenever generating any game art (sprites, sheets, animations, tiles, UI, FX) — then ALSO load the matching specialist skill: game-animation-frames for anything that moves, game-tilesets for tiles/terrain, game-character-consistency for recurring characters, game-ui-icons for UI and icons.

evalix098/tiktoklive

Deep guide for CHARACTER IDENTITY across images: turnarounds (front/side/ back), state and damage variants, palette swaps, equipment changes, and same-character-in-context sets. Use whenever generating character turnarounds, character sheets, variants of an existing sprite, or any same-subject multi-image set. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game TILE assets: seamless tileable textures, terrain transition tilesets, autotiles, and ground/platform tiles. Use whenever generating tileable textures, tilesets, terrain transitions, or seamless patterns. Complements game-asset-core.

evalix098/tiktoklive

Deep guide for game UI assets: buttons with interaction states, panels, bars, wordmark logos, and icon sets. Use whenever generating game UI elements, HUD assets, inventory icons, icon sets, buttons, or title logos. Complements game-asset-core.

evalix098/tiktoklive

Generate production-oriented 2D game maps with `imagine_text_to_image`: RPG/top-down maps, side-scroller parallax stages, tilemaps, layered raster maps, prop packs, collision zones, and walkable areas. Use when building browser games that need real map art (not pure code-drawn tiles), layered props, or map collision metadata. Triggers on "map", "level", "stage", "tilemap", "overworld", "dungeon", "side scroller background", "prop pack", "2D map".

evalix098/tiktoklive

Generate and postprocess 2D game sprites and animation sheets: pixel-art characters, NPCs, creatures, spells, projectiles, impacts, props, summons, and transparent PNG/GIF exports. Use when building browser games that need real sprite sheets (not code-drawn placeholders), matching a map art style, or producing magenta-background sheets for chroma-key cleanup. Triggers on "sprite", "sprite sheet", "animation sheet", "pixel art character", "walk cycle", "attack animation", "projectile sprite", "2D game asset".

evalix098/tiktoklive

How to use the Imagine tools in Grok Build: imagine_text_to_image, imagine_image_to_image, imagine_reference_to_image, imagine_text_to_video, imagine_image_to_video, imagine_reference_to_video, and render_file for chat previews. When to build a visual with code instead of generating it, prompt-craft, reference-first handling of real people, factual grounding, and asset-consistency. Load this whenever generating or editing an image or video is on the table. Tool-usage-driven, not triggered by a user merely mentioning images.

evalix098/tiktoklive

Peer-to-peer realtime multiplayer over WebRTC data channels: every user of the deployed app connects directly to every other user (full mesh), the server only brokers the handshake at /api/rtc. Lowest possible latency, zero per-message server cost. Use for 2-8 player co-op/casual realtime: shared cursors, drawing, party games, casual action. Triggers: p2p, peer to peer, webrtc, low latency multiplayer, direct connection.

evalix098/tiktoklive

Share-link previews and app identity for apps on *.grok.me: the injector-owned og:image card, the SVG favicon, and PWA icons for installable apps. Use when scaffolding, renaming, or restyling the app — and for share / unfurl / OG / Twitter card questions. A custom 1200×630 card from the app's own art is the default — games of every kind (DOM board/word games included), whimsical apps, creative tools, and brand-forward pages; only plain utilities keep the placeholder. Always run the brand-asset pass as a `task` subagent and never wait for it. Triggers on "share", "rename", "app name", "OG", "Open Graph", "twitter card", "unfurl", "og:image", "og:type", "x:game:image", "x-banner", "link preview", "social card", "thumbnail", "preview image", "favicon", "app icon", "PWA", "manifest", "installable", "home screen", "SEO", "meta description".

evalix098/tiktoklive

Official Three.js API and TSL (Three.js Shading Language) reference for LLM code generation. Load when writing or debugging three.js / WebGL / WebGPU / custom materials / shaders / GLTF / advanced three APIs beyond basic game loop/controls. Prefer building-games for game correctness (loop, WASD, camera, orientation); use this skill for full API/TSL depth. Triggers on "three.js", "threejs", "WebGPU", "TSL", "NodeMaterial", "shader", "GLTF", "MeshStandard", "OrbitControls", "WebGLRenderer".

evalix098/tiktoklive

Grok Build only. Turn a 2D character still into denser animation sprites via imagine_text_to_image base → imagine_image_to_video (6s/10s run-in-place) → ffmpeg frames → magenta chroma-key → dense sampled strips/grids/GIFs. Use when the user wants video-to-sprite, smoother run/walk cycles, or denser intermediate poses. Prefer generate2dsprite for crisp production pixel sheets. Triggers on "video to sprite", "imagine_image_to_video sprite", "dense walk cycle", "smooth run animation from video".

evalix098/tiktoklive

Call the xAI API (Grok) from this app's server code using the injected XAI_API_KEY: chat/LLM features, image and video generation (Imagine), and voice (text-to-speech). Use when the app needs any "AI" / "assistant" / "chatbot" / "Grok" functionality, runtime image/video generation, or speech. Triggers on "AI", "LLM", "chatbot", "assistant", "Grok", "xAI", "generate text", "summarize", "generate image", "AI video", "voice", "text to speech", "TTS", "OpenAI" (use xAI instead).

相關技能