Skip to content

kubuskotak/tyr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tyr

Just Simple SQL Builder and DB Helper

$ go get -u github.com/kubuskotak/tyr
import "github.com/kubuskotak/tyr"

Driver support

  • MySQL
  • PostgreSQL
  • SQLite3
  • MsSQL

Examples

SelectStmt with where-value interpolation

buf := NewBuffer()

ids := []int64{1, 2, 3, 4, 5}
Select("*").From("suggestions").Where("id IN ?", ids).ToSQL(dialect.MySQL, buf)

SelectStmt with joins

buf := NewBuffer()

Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id").ToSQL(dialect.MySQL, buf)

Select("*").From("suggestions").
LeftJoin("subdomains", "suggestions.subdomain_id = subdomains.id").ToSQL(dialect.MySQL, buf)

// join multiple tables
Select("*").From("suggestions").
Join("subdomains", "suggestions.subdomain_id = subdomains.id").
Join("accounts", "subdomains.accounts_id = accounts.id").ToSQL(dialect.MySQL, buf)

SelectStmt with raw SQL

SelectBySql("SELECT `title`, `body` FROM `suggestions` ORDER BY `id` ASC LIMIT 10")

InsertStmt adds data from struct

type Suggestion struct {
ID        int64
Title        NullString
CreatedAt    time.Time
}
sugg := &Suggestion{
Title:        NewNullString("Gopher"),
CreatedAt:    time.Now(),
}

buf := NewBuffer()
InsertInto("suggestions").
Columns("title").
Record(&sugg).ToSQL(dialect.MySQL, buf)

InsertStmt adds data from value

InsertInto("suggestions").
Pair("title", "Gopher").
Pair("body", "I love go.")

Thanks

Inspiration and fork from these awesome libraries:

About

Just Simple SQL Builder and DB Helper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages