Sqle
A package for fast mapping SQL rows to structures, maps and slices
Install / Use
/learn @lazada/SqleREADME
sqle

The sqle package is an extension of the standard database/sql package.
Features
- fully implements the
database/sqlinterface; - it is fast, sometimes very fast (has a minimum overhead);
Scanmethod can take composite types as arguments, such as pointers to structures (including nested ones), maps and slices;ColumnsandColumnTypesmethods cache the returned result.
Prerequisites
This package requires Go 1.8 or later.
Installation
go get -u github.com/lazada/sqle
Usage
There are two ways of using this package:
- by replacing standard
database/sqlpackage with this package in your imports; - by wrapping specific standard
database/sqlobjects using theWrapfunction.
Examples
Additional examples of usage are available in rows_test.go, row_test.go and wrap_test.go.
Working with structures
As it was:
import "database/sql"
type User struct {
Id int32
Name string
Email string
Created time.Time
Updated time.Time
}
db, err := sql.Open(`sqlite3`, `testdata/testdata.db`)
if err != nil {
log.Fatalln(err)
}
user := new(User)
err = db.QueryRowContext(ctx, `SELECT * FROM users WHERE id = ?`, userId).
Scan(&user.Id, &user.Name, &user.Email, &user.Created, &user.Updated)
if err != nil {
log.Fatalln(err)
}
It is now:
import sql "github.com/lazada/sqle"
type User struct {
Id int32 `sql:"id"`
Name string `sql:"name"`
Email string `sql:"email"`
Created time.Time `sql:"created"`
Updated time.Time `sql:"updated"`
}
db, err := sql.Open(`sqlite3`, `testdata/testdata.db`)
if err != nil {
log.Fatalln(err)
}
user := new(User)
err = db.QueryRowContext(ctx, `SELECT * FROM users WHERE id = ?`, userId).Scan(user)
if err != nil {
log.Fatalln(err)
}
Working with maps
As it was (simplified example):
import "database/sql"
db, err := sql.Open(`sqlite3`, `testdata/testdata.db`)
if err != nil {
log.Fatalln(err)
}
var (
userId int32
userName, userEmail string
userCreated, userUpdated time.Time
)
err = db.QueryRowContext(ctx, `SELECT * FROM users WHERE id = ?`, userId).
Scan(&userId, &userName, &userEmail, &userCreated, &userUpdated)
if err != nil {
log.Fatalln(err)
}
user := map[string]interface{}{
`id`: userId,
`name`: userName,
`email`: userEmail,
`created`: userCreated,
`updated`: userUpdated,
}
It is now:
import sql "github.com/lazada/sqle"
db, err := sql.Open(`sqlite3`, `testdata/testdata.db`)
if err != nil {
log.Fatalln(err)
}
user := make(map[string]interface{})
err = db.QueryRowContext(ctx, `SELECT * FROM users WHERE id = ?`, userId).Scan(user)
if err != nil {
log.Fatalln(err)
}
Related Skills
oracle
347.6kBest practices for using the oracle CLI (prompt + file bundling, engines, sessions, and file attachment patterns).
xurl
347.6kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
prose
347.6kOpenProse VM skill pack. Activate on any `prose` command, .prose files, or OpenProse mentions; orchestrates multi-agent workflows.
Command Development
108.4kThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
