Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // database
- package main
- import (
- "fmt"
- "time"
- "gopkg.in/pg.v3"
- )
- var user struct {
- CreatedAt time.Time
- ID int64
- Login string
- Password string
- IsActive bool
- }
- func main() {
- db := pg.Connect(&pg.Options{
- Host: "127.0.0.1",
- User: "user",
- Password: "12345",
- Database: "database",
- })
- _, er := db.Exec(`SELECT SUM(1 + 1)`)
- if er != nil {
- fmt.Print("ERROR!!!")
- }
- user.Login = "qwerty"
- user.Password = "12345"
- _, errr := db.QueryOne(user, `INSERT INTO "user" ("login", "password", "is_active", "created_at")
- VALUES (?login, ?password, ?is_active, current_timestamp)
- RETURNING id;`, user)
- if errr != nil {
- fmt.Print(errr.Error())
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement