-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
29 lines (27 loc) · 958 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import (
"database/sql"
"log"
"sequelie"
)
func main() {
if err := sequelie.ReadDirectory("examples/"); err != nil {
log.Fatal("failed to read dirs: ", err)
}
// For example purposes, we'll use this. You are free to use anything as long as it can support
// using raw queries since that is the core of what Sequelie does.
sequel, err := sql.Open("postgres", "postgres://127.0.0.1:5432")
if err != nil {
log.Fatal("failed to connect to postgres: ", err)
}
// In this example, we are retrieving the "books.get_with_field" query from the books.sql and
// making it basically like "books.get" as an example.
query := sequelie.Get("books.get_with_field").Interpolate(sequelie.Map{"field": "id"})
rows, err := sequel.Query(query, 0)
if err != nil {
log.Fatal("failed to get rows in postgres: ", err)
return
}
defer rows.Close()
// You can then do whatever you'd like to do with the rows, if you prefer doing it manually.
}