mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright 2018 Huan Du. All rights reserved.
|
|
// Licensed under the MIT license that can be found in the LICENSE file.
|
|
|
|
package sqlbuilder
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func ExampleInsertBuilder() {
|
|
ib := NewInsertBuilder()
|
|
ib.InsertInto("demo.user")
|
|
ib.Cols("id", "name", "status", "created_at")
|
|
ib.Values(1, "Huan Du", 1, Raw("UNIX_TIMESTAMP(NOW())"))
|
|
ib.Values(2, "Charmy Liu", 1, 1234567890)
|
|
|
|
sql, args := ib.Build()
|
|
fmt.Println(sql)
|
|
fmt.Println(args)
|
|
|
|
// Output:
|
|
// INSERT INTO demo.user (id, name, status, created_at) VALUES (?, ?, ?, UNIX_TIMESTAMP(NOW())), (?, ?, ?, ?)
|
|
// [1 Huan Du 1 2 Charmy Liu 1 1234567890]
|
|
}
|
|
|
|
func ExampleInsertBuilder_replaceInto() {
|
|
ib := NewInsertBuilder()
|
|
ib.ReplaceInto("demo.user")
|
|
ib.Cols("id", "name", "status", "created_at")
|
|
ib.Values(1, "Huan Du", 1, Raw("UNIX_TIMESTAMP(NOW())"))
|
|
ib.Values(2, "Charmy Liu", 1, 1234567890)
|
|
|
|
sql, args := ib.Build()
|
|
fmt.Println(sql)
|
|
fmt.Println(args)
|
|
|
|
// Output:
|
|
// REPLACE INTO demo.user (id, name, status, created_at) VALUES (?, ?, ?, UNIX_TIMESTAMP(NOW())), (?, ?, ?, ?)
|
|
// [1 Huan Du 1 2 Charmy Liu 1 1234567890]
|
|
}
|