Documentation ¶
Overview ¶
Package dotsql provides a way to separate your code from SQL queries.
It is not an ORM, it is not a query builder. Dotsql is a library that helps you keep sql files in one place and use it with ease.
For more usage examples see https://github.com/gchaincl/dotsql
Index ¶
- type DotSql
- func (d DotSql) Exec(db Execer, name string, args ...interface{}) (sql.Result, error)
- func (d DotSql) Prepare(db Preparer, name string) (*sql.Stmt, error)
- func (d DotSql) Query(db Queryer, name string, args ...interface{}) (*sql.Rows, error)
- func (d DotSql) QueryMap() map[string]string
- func (d DotSql) Raw(name string) (string, error)
- type Execer
- type Preparer
- type Queryer
- type Scanner
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DotSql ¶
type DotSql struct {
// contains filtered or unexported fields
}
DotSql represents a dotSQL queries holder.
func LoadFromFile ¶
LoadFromFile imports SQL queries from the file.
Example ¶
package main import ( "database/sql" "github.com/gchaincl/dotsql" ) func main() { db, err := sql.Open("sqlite3", ":memory:") if err != nil { panic(err) } dot, err := dotsql.LoadFromFile("queries/users.sql") if err != nil { panic(err) } /* users.sql looks like: --name: create-user INSERT INTO users (email) VALUES(?) --name: find-user-by-email SELECT email FROM users WHERE email = ? */ if _, err := dot.Exec(db, "create-user", "user@example.com"); err != nil { panic(err) } rows, err := dot.Query(db, "find-user-by-email", "user@example.com") if err != nil { panic(err) } defer rows.Close() }
Output:
func LoadFromString ¶
LoadFromString imports SQL queries from the string.
func Merge ¶
Merge takes one or more *DotSql and merge its queries It's in-order, so the last source will override queries with the same name in the previous arguments if any.
Click to show internal directories.
Click to hide internal directories.