sql-embedder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesesql-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 files into TypeScript modules (). Each SQL
statement with a preceding comment becomes an exported constant:
.sql.sql.tsbooks.sql → books.sql.ts
queries.sql → queries.sql.ts该工具会将文件转换为TypeScript模块()。每条带有前置注释的SQL语句都会成为一个导出常量:
.sql.sql.tsbooks.sql → books.sql.ts
queries.sql → queries.sql.tsIdentifying 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 files directly. These files are auto-generated and any
manual changes will be overwritten.
.sql.tsIf you see the generated file comment, find the corresponding file (same
name, without the extension) and edit that instead.
.sql.ts绝对不要直接编辑文件。这些文件是自动生成的,任何手动修改都会被覆盖。
.sql.ts如果你看到上述生成文件的注释,请找到对应的文件(同名,不带扩展名)并编辑该文件。
.sql.tsCorrect Workflow
正确工作流程
- Edit the source file (e.g.,
.sql)books.sql - Identify the generation command by checking the project's task runner config:
- → look for a
deno.jsontaskgenerate - → look for a
package.jsonscript ingeneratescripts - → look for a
Makefiletargetgenerate - → look for a
justfilerecipegenerate
- Run the identified command to regenerate the TypeScript files
- 编辑源文件(例如
.sql)books.sql - 通过检查项目的任务运行器配置来确定生成命令:
- → 查找
deno.json任务generate - → 查找
package.json中的scripts脚本generate - → 查找
Makefile目标generate - → 查找
justfile配方generate
- 运行找到的命令以重新生成TypeScript文件
Example
示例
To add a new query called :
findBooksByAuthor-
Edit:
books.sqlsql-- findBooksByAuthor finds all books by a given author. SELECT * FROM books WHERE author_id = ?; -
Check the project config (e.g.,,
deno.json) for the generate commandpackage.json -
Run the generation command
The new query will appear in as an exported constant.
books.sql.ts要添加一个名为的新查询:
findBooksByAuthor-
编辑:
books.sqlsql-- findBooksByAuthor finds all books by a given author. SELECT * FROM books WHERE author_id = ?; -
检查项目配置(例如、
deno.json)中的生成命令package.json -
运行生成命令
新查询将作为导出常量出现在中。
books.sql.ts