@@ -3,50 +3,25 @@ package database
33import (
44 "context"
55 "fmt"
6- "github.com/creasty/defaults"
7- "github.com/icinga/icinga-go-library/logging"
8- "github.com/icinga/icinga-go-library/utils"
9- "go.uber.org/zap/zapcore"
106 "golang.org/x/sync/errgroup"
117 "time"
128)
139
1410func ExampleUpsertStreamed () {
1511 var (
16- testEntites = []MockEntity {
12+ testEntites = []User {
1713 {
Id :
1 ,
Name :
"test1" ,
Age :
10 ,
Email :
"[email protected] " },
1814 {
Id :
2 ,
Name :
"test2" ,
Age :
20 ,
Email :
"[email protected] " },
1915 }
20- g , ctx = errgroup .WithContext (context .Background ())
21- entities = make (chan MockEntity , len (testEntites ))
22- defaultOptions Options
16+ g , ctx = errgroup .WithContext (context .Background ())
17+ entities = make (chan User , len (testEntites ))
18+ logs = getTestLogging ()
19+ log = logs .GetLogger ()
20+ db = getTestDb (logs )
21+ err error
2322 )
2423
25- logs , err := logging .NewLoggingFromConfig (
26- "Icinga Go Library" ,
27- logging.Config {Level : zapcore .DebugLevel , Output : "console" , Interval : time .Second * 10 },
28- )
29- if err != nil {
30- utils .PrintErrorThenExit (err , 1 )
31- }
32-
33- log := logs .GetLogger ()
34-
35- err = defaults .Set (& defaultOptions )
36- if err != nil {
37- log .Fatalf ("cannot set default options: %v" , err )
38- }
39-
40- db , err := NewDbFromConfig (
41- & Config {Type : "sqlite" , Database : ":memory:example-upsert" , Options : defaultOptions },
42- logs .GetChildLogger ("database" ),
43- RetryConnectorCallbacks {},
44- )
45- if err != nil {
46- log .Fatalf ("cannot create database: %v" , err )
47- }
48-
49- _ , err = db .Query ("CREATE TABLE IF NOT EXISTS mock_entity (id INTEGER PRIMARY KEY, name VARCHAR(255), age INTEGER, email VARCHAR(255))" )
24+ _ , err = db .Query ("CREATE TABLE IF NOT EXISTS user (id INTEGER PRIMARY KEY, name VARCHAR(255), age INTEGER, email VARCHAR(255))" )
5025 if err != nil {
5126 log .Fatalf ("cannot create table in db: %v" , err )
5227 }
@@ -63,9 +38,9 @@ func ExampleUpsertStreamed() {
6338
6439 time .Sleep (time .Second )
6540
66- testSelect := & []MockEntity {}
41+ testSelect := & []User {}
6742
68- err = db .Select (testSelect , "SELECT * FROM mock_entity " )
43+ err = db .Select (testSelect , "SELECT * FROM user " )
6944 if err != nil {
7045 log .Fatalf ("cannot select from db: %v" , err )
7146 }
0 commit comments