Skip to content

bytesystem/squirrel

 
 

Repository files navigation

Squirrel - fluent SQL generator for Go

GoDoc Build Status

Squirrel is not an ORM.

Squirrel helps you build SQL queries from composable parts:

users := Select("*").From("users")

active := users.Where(Eq{"deleted_at": nil})

sql, args, err := active.ToSql()

sql == "SELECT * FROM users WHERE deleted_at IS NULL"

Squirrel can also execute queries directly:

stooges := users.Where(Eq{"username": []string{"moe", "larry", "curly", "shemp"}})
three_stooges := stooges.Limit(3)
rows, err := three_stooges.RunWith(db).Query()

// Behaves like:
rows, err := db.Query("SELECT * FROM users WHERE username IN (?,?,?,?) LIMIT 3",
                      "moe", "larry", "curly", "shemp")

Squirrel makes conditional query building a breeze:

if len(q) > 0 {
    users = users.Where("name LIKE ?", fmt.Sprint("%", q, "%"))
}

Squirrel wants to make your life easier:

// StmtCache caches Prepared Stmts for you
dbCache := NewStmtCache(db)

// StatementBuilder keeps your syntax neat
mydb := StatementBuilder.RunWith(dbCache)
select_users := mydb.Select("*").From("users")

License

Builder is released under the MIT License.

About

Fluent SQL generation for golang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors