Skip to content

Latest commit

 

History

History
50 lines (43 loc) · 1.2 KB

README.md

File metadata and controls

50 lines (43 loc) · 1.2 KB

squeeze

SQL template manager

Writing SQL is nice, embedding SQL in application code is not. Squeeze provides an easy way to keep your SQL query templates separate.

go get go.soon.build/squeeze
  1. Write templates
-- ./templates/user/user.sql
{{define "byID"}}
SELECT *
FROM "{{.Table}}"
WHERE id = $1
{{end}}
  1. Load templates into squeeze store
import (
    "go.soon.build/squeeze"
    "go.soon.build/squeeze/source"
)

sqt, err := squeeze.New(source.NewDirectory("./templates"))
if err != nil {
    // handle err
}
  1. Build a query from a template
qry := sqt.Parse("user.byID", struct{
    Table string
}, {
    Table: "page",
})

Sourcing Templates

The directory source, as used above, reads templates from a directory tree. To source templates from alternative locations (eg. bundled static files) implement the squeeze.Sourcer interface to add templates to the store or use one of the existing source implementations: