Created
December 10, 2015 07:48
-
-
Save MarchLiu/37709fe08042443eb794 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/Dwarfartisan/pgears" | |
"time" ) | |
var Engine *pgears.Engine | |
type Usertbl struct{ | |
Name string `field:"name" pk:"true"` | |
Signup_date time.Time `field:"signup_date"` | |
} | |
func main(){ | |
Engine, _ = pgears.CreateEngine("postgres://dbuser:pass | |
[email protected]/exampledb?sslmode=disable") | |
var usertbl Usertbl | |
Engine.MapStructTo(&usertbl, "usertbl") | |
var usertbl_m Usertbl | |
usertbl_m.Name = "test" | |
usertbl_m.Signup_date = time.Now() | |
err := Engine.Insert(&usertbl_m) | |
if err != nil { | |
fmt.Println(err) | |
return } | |
fmt.Println("insert ok") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
具体在这个例子中,第20行的判断,遇到错误完全可以直接panic