Skip to content

Releases: alimy/yesql

v1.0.0

30 Mar 21:51
2d8f0db
Compare
Choose a tag to compare
  • first v1.0 release

v0.9.1

30 Mar 21:44
70d97c0
Compare
Choose a tag to compare
  • PreparexContext interface add Rebind(...) method

v0.9.0

30 Mar 21:24
ba68ad5
Compare
Choose a tag to compare
  • 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

30 Mar 19:37
cd19e59
Compare
Choose a tag to compare
  • add struct type generate automatic by sql file support

v0.7.0

30 Mar 09:33
25abc87
Compare
Choose a tag to compare
  • optimize sql parser abstract
  • rename SetDefaultQueryHooks(...) => SetDefaultQueryHook(...)
  • optimize SetDefaultPrepareHook(...) logic that reset default prepare hook if give nil param

v0.6.0

29 Mar 14:49
9811157
Compare
Choose a tag to compare
  • remove SetDefaultPrepareScanner(scanner PrepareScanner)
  • add SetDefaultPrepareHook(hook PrepareHook)

v0.5.1

29 Mar 13:29
3c2233e
Compare
Choose a tag to compare
  • trim $ when -- name: value is start with $ in sql file
-- name: $comments
-- name of $comments will equal to comments becase '$' is special character for struct tag value
SELECT *
FROM comments;

v0.5.0

29 Mar 13:21
9b30917
Compare
Choose a tag to compare
  • 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)
	}
}

v0.4.0

28 Mar 12:14
Compare
Choose a tag to compare
  • add PrepareContext/PreparexContext abstract interface

v0.2.0

27 Mar 21:07
Compare
Choose a tag to compare
  • rename type yesql.Namespace to yesql.Scope
  • add Use(...)/UseSqlx(...)/SetDefaultQueryHooks(...) help function