Skip to content

Commit

Permalink
DOC: add ExampleInsertStmt and ExampleDeleteStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorchu committed May 10, 2018
1 parent d562ec9 commit 106750d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package dbr

import (
"fmt"
"time"
)

func ExampleOpen() {
// create a connection (e.g. "postgres", "mysql", or "sqlite3")
conn, _ := Open("postgres", "...", nil)
Expand Down Expand Up @@ -80,6 +85,26 @@ func ExampleInsertStmt_Pair() {
Pair("body", "I love go.")
}

func ExampleInsertStmt_Record() {
type Suggestion struct {
ID int64
Title NullString
CreatedAt time.Time
}
sugg := &Suggestion{
Title: NewNullString("Gopher"),
CreatedAt: time.Now(),
}
sess := mysqlSession
sess.InsertInto("suggestions").
Columns("id", "title").
Record(&sugg).
Exec()

// id is set automatically
fmt.Println(sugg.ID)
}

func ExampleUpdateStmt() {
sess := mysqlSession
sess.Update("suggestions").
Expand All @@ -88,6 +113,12 @@ func ExampleUpdateStmt() {
Where("id = ?", 1)
}

func ExampleDeleteStmt() {
sess := mysqlSession
sess.DeleteFrom("suggestions").
Where("id = ?", 1)
}

func ExampleTx() {
sess := mysqlSession
tx, err := sess.Begin()
Expand Down

0 comments on commit 106750d

Please sign in to comment.