querybag
querybag copied to clipboard
Overview
Querybag is a library that loads all SQL files from a specific directory, and it allows you to access them by using their file name, as in the example below.
This way you don't have extremely long strings of SQL statements in your code, but you can have them in nice, separate, SQL files instead.
License
Querybag is licensed under a MIT license.
Installation
A simple go get github.com/Machiel/querybag should suffice.
Usage
Example
queries/retrieve_user_by_id.sql
SELECT *
FROM user
WHERE id = ?
package main
import (
"fmt"
"database/sql"
"github.com/Machiel/querybag"
)
var db *sql.DB
func main() {
userID := 12
b, err := querybag.New("queries") // Load all SQL files from queries directory
if err != nil {
panic(err)
}
rows, err := db.Query(b.Get("retrieve_user_by_id"), userID)
// Business as usual
}