Releases: alimy/yesql
Releases · alimy/yesql
v1.0.0
v0.9.1
v0.9.0
- fixed generate code of sql query string is not correct error
- add
SetDefaultGenerator(g Generator)
function to set default generator - rename
Generate(g Generator, sqlFilePath string, dstPath string, pkgName string, opts ...option) error
=>Generate(sqlFilePath string, dstPath string, pkgName string, opts ...option) error
To generate code just do this:
package main
import (
"log"
"github.com/alimy/yesql"
)
//go:generate go run $GOFILE
func main() {
log.Println("Yesql generate code start")
if err := yesql.Generate("yesql.sql", "auto", "yesql"); err != nil {
log.Fatalf("generate code occurs error: %s", err)
}
log.Println("Yesql generate code finish")
}
v0.8.0
v0.7.0
v0.6.0
v0.5.1
v0.5.0
- re-define
SQLQuery.ListQuery(namespace string) (QueryMap, error)
=>SQLQuery.ListQuery(namespace ...string) (QueryMap, error)
var query SQLQuery
// get default QueryMap
defaultQuery, _ := query.ListQuery()
// get deafult QueryMap by empty namespace
defaultQuery, _ = query.ListQuery("")
// get QueryMap by namespace
namespaceQuery, _ := query.ListQuery("namespace")
- use
$name
in struct tag value to get default namespace's sql query
var yesqlBytes = `
-- name: simple
-- raw: 1
SELECT * FROM simple;
-- name: multiline@namespace
SELECT *
FROM multiline
WHERE line = 42;
`
func TestScan(t *testing.T) {
var q struct {
yesql.Namespace `yesql:"namespace"`
Ignore string
SimpleQuery string `yesql:"$simple"`
RawQuery string `yesql:"multiline"`
}
queries := yesql.MustParseBytes(yesqlBytes)
err := yesql.Scan(&q, queries, NewPrepareHook(nil))
if err != nil {
t.Errorf("[q] failed to scan raw query to struct: %s", err)
}
if q.SimpleQuery != `SELECT * FROM simple;` {
t.Errorf("[q] want simple query but got %s", q.SimpleQuery)
}
if q.RawQuery != `SELECT * FROM multiline WHERE line = 42;` {
t.Errorf("[q] want raw query but got %s", q.RawQuery)
}
}