Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqlf

GoDoc Build Status

Package sqlf provides Printf-like methods to generate SQL queries with placeholders. It produces query and args which can be passed to database/sql APIs. It assumes a special format verb "%_" in addition to those of package fmt, which expands to SQL placeholders.

For example, see the example for Printf.

Examples

Printf

query, args := sqlf.Printf(
    "SELECT %s FROM %s WHERE col1 = %_ AND col2 IN (%_)",
    "id",    // SELECT %s
    "table", // FROM %s
    "x",     // col1 = %_
    []interface{}{1, 2, 3}, // col2 IN (%_)
).BuildSQL()

fmt.Println(query)
fmt.Println(args)

Output:

SELECT id FROM table WHERE col1 = ? AND col2 IN (?,?,?)
[x 1 2 3]

Author

motemen https://motemen.github.io/

About

Simple and obvious Printf-like SQL generator

Resources

Stars

38 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages