sql-embedder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

sql-embedder

sql-embedder

This skill provides guidance for working with sql-embedder generated files.
本技能为使用sql-embedder生成的文件提供操作指导。

About sql-embedder

关于sql-embedder

sql-embedder embeds SQL into TypeScript source code. It makes developing and distributing TypeScript applications easier when you need access to SQL databases at runtime—no special permissions required. It generates statically analyzable modules.
sql-embedder可将SQL嵌入到TypeScript源代码中。当你需要在运行时访问SQL数据库时,它能让TypeScript应用的开发和分发变得更简单——无需特殊权限。它会生成可静态分析的模块。

How It Works

工作原理

The tool converts
.sql
files into TypeScript modules (
.sql.ts
). Each SQL statement with a preceding comment becomes an exported constant:
books.sql       →  books.sql.ts
queries.sql     →  queries.sql.ts
该工具会将
.sql
文件转换为TypeScript模块(
.sql.ts
)。每条带有前置注释的SQL语句都会成为一个导出常量:
books.sql       →  books.sql.ts
queries.sql     →  queries.sql.ts

Identifying Generated Files

识别生成的文件

Generated files always start with this exact comment:
typescript
// This file was generated by sql-embedder. Do not edit manually.
生成的文件开头总会有如下精确注释:
typescript
// This file was generated by sql-embedder. Do not edit manually.

Critical Rule

关键规则

NEVER edit
.sql.ts
files directly.
These files are auto-generated and any manual changes will be overwritten.
If you see the generated file comment, find the corresponding
.sql
file (same name, without the
.ts
extension) and edit that instead.
绝对不要直接编辑
.sql.ts
文件
。这些文件是自动生成的,任何手动修改都会被覆盖。
如果你看到上述生成文件的注释,请找到对应的
.sql
文件(同名,不带
.ts
扩展名)并编辑该文件。

Correct Workflow

正确工作流程

  1. Edit the source
    .sql
    file (e.g.,
    books.sql
    )
  2. Identify the generation command by checking the project's task runner config:
    • deno.json
      → look for a
      generate
      task
    • package.json
      → look for a
      generate
      script in
      scripts
    • Makefile
      → look for a
      generate
      target
    • justfile
      → look for a
      generate
      recipe
  3. Run the identified command to regenerate the TypeScript files
  1. 编辑源
    .sql
    文件(例如
    books.sql
  2. 通过检查项目的任务运行器配置来确定生成命令:
    • deno.json
      → 查找
      generate
      任务
    • package.json
      → 查找
      scripts
      中的
      generate
      脚本
    • Makefile
      → 查找
      generate
      目标
    • justfile
      → 查找
      generate
      配方
  3. 运行找到的命令以重新生成TypeScript文件

Example

示例

To add a new query called
findBooksByAuthor
:
  1. Edit
    books.sql
    :
    sql
    -- findBooksByAuthor finds all books by a given author.
    SELECT * FROM books WHERE author_id = ?;
  2. Check the project config (e.g.,
    deno.json
    ,
    package.json
    ) for the generate command
  3. Run the generation command
The new query will appear in
books.sql.ts
as an exported constant.
要添加一个名为
findBooksByAuthor
的新查询:
  1. 编辑
    books.sql
    sql
    -- findBooksByAuthor finds all books by a given author.
    SELECT * FROM books WHERE author_id = ?;
  2. 检查项目配置(例如
    deno.json
    package.json
    )中的生成命令
  3. 运行生成命令
新查询将作为导出常量出现在
books.sql.ts
中。