Skip to content

thisissoon/squeeze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

SQL template manager

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages