Advertisement
Guest User

Untitled

a guest
Nov 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. // database
  2. package main
  3.  
  4. import (
  5. "fmt"
  6. "time"
  7. "gopkg.in/pg.v3"
  8. )
  9.  
  10. var user struct {
  11. CreatedAt time.Time
  12. ID int64
  13. Login string
  14. Password string
  15. IsActive bool
  16. }
  17.  
  18. func main() {
  19. db := pg.Connect(&pg.Options{
  20. Host: "127.0.0.1",
  21. User: "user",
  22. Password: "12345",
  23. Database: "database",
  24. })
  25.  
  26. _, er := db.Exec(`SELECT SUM(1 + 1)`)
  27. if er != nil {
  28. fmt.Print("ERROR!!!")
  29. }
  30. user.Login = "qwerty"
  31. user.Password = "12345"
  32. _, errr := db.QueryOne(user, `INSERT INTO "user" ("login", "password", "is_active", "created_at")
  33. VALUES (?login, ?password, ?is_active, current_timestamp)
  34. RETURNING id;`, user)
  35.  
  36. if errr != nil {
  37. fmt.Print(errr.Error())
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement