Documentation
¶
Overview ¶
Package sqload provides functions to load SQL code from strings or .sql files into tagged struct fields
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromString ¶
FromString loads the SQL code from the string passed and stores the queries in the struct pointed to by v, v must be a pointer to a struct with tags, and each tag indicates what query will be stored in what field. Example:
package main
import (
"fmt"
"os"
"github.com/midir99/sqload"
)
type UserQueries struct {
FindUserById string `query:"FindUserById"`
UpdateUserFirstNameById string `query:"UpdateUserFirstNameById"`
}
func main() {
sql := `
-- query: FindUserById
SELECT * FROM user WHERE id = :id;
-- query: UpdateUserFirstNameById
UPDATE user SET first_name = :first_name WHERE id = :id;
`
userQueries := UserQueries{}
err := sqload.FromString(sql, &userQueries)
if err != nil {
fmt.Printf("error loading user queries: %s\n", err)
os.Exit(1)
}
fmt.Printf("FindUserById: %s", userQueries.FindUserById)
fmt.Printf("UpdateUserFirstNameById: %s", userQueries.UpdateUserFirstNameById)
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.