sqlc将 SQL 编译为类型安全的 Go
sqlc 从 SQL 生成完全类型安全的成语 Go 代码。下面是它的工作原理:
- 你使用 SQL 编写查询。
- 你运行 sqlc 以生成具有这些查询的类型安全接口的代码。
- 你编写调用生成代码的应用程序代码。
sqlc 可以使用这个 SQL:
CREATE TABLE authors ( id BIGSERIAL PRIMARY KEY, name text NOT NULL, bio text ); -- name: GetAuthor :one SELECT * FROM authors WHERE id = $1 LIMIT 1;
并自动生成以下 Go 代码:
package db import ( "context" "database/sql" ) type Author struct { ID int64 Name string Bio sql.NullString } const getAuthor = `-- name: GetAuthor :one SELECT id, name, bio FROM authors WHERE id = $1 LIMIT 1 ` type Queries struct { db *sql.DB } func (q *Queries) GetAuthor(ctx context.Context, id int64) (Author, error) { row := q.db.QueryRowContext(ctx, getAuthor, id) var i Author err := row.Scan(&i.ID, &i.Name, &i.Bio) return i, err }
sqlc 的灵感来自 PugSQL 和 HugSQL。
评论
ncc将 Node.js 项目编译为单个文件
ncc是一个简单的CLI,可以将Node.js项目编译为单个文件,包括项目的依赖与gcc-style。功能将最小包发布到npm仅将相关应用程序代码发送到无服务器环境(云函数)不用浪费时间配置捆绑包通常
ncc将 Node.js 项目编译为单个文件
0
Nimporter导入时将 Nim 编译为 Python
Nimporter是一个Python库,可以简单地将Nim源代码文件导入为类似Python模块的代码,与Python代码无缝地结合使用。特性:性能:Nim编译为C无需编写C即可降低云计算成本利用两种语
Nimporter导入时将 Nim 编译为 Python
0
Queryx类型安全 Go ORM
Queryx是Schema优先且类型安全的GoORM。Queryx使用schema.hcl来描述数据库,在以下例子中定义了数据库环境以及数据库模型。schema.hcldatabase"db"{ada
Queryx类型安全 Go ORM
0
CrossBridgeC/C++编译为SWF
今天Adobe正式宣布将FlasCC开源!FlasCC是可以将C/C++程序编译为SWF的编译器,这使得无数客户端游戏变为页游成为可能!而CrossBridge就是开源版的FlasCC。
CrossBridgeC/C++编译为SWF
0
ElectroDB类型安全的 DynamoDB 库
ElectroDB是一个DynamoDB库,以方便使用复杂的分层关系建模和实现单表设计,同时保持你的查询代码可读性。特性:与现有表一起使用-ElectroDB简化了DocumentClient参数的构
ElectroDB类型安全的 DynamoDB 库
0