@@ -2,81 +2,42 @@ package main
22
33import (
44 "context"
5- "flag"
65 "fmt"
76 "os"
87 "path"
8+ "time"
99
1010 environ "github.com/ydb-platform/ydb-go-sdk-auth-environ"
1111
12- ydb "github.com/ydb-platform/ydb-go-sdk/v3"
12+ "github.com/ydb-platform/ydb-go-sdk/v3"
1313 "github.com/ydb-platform/ydb-go-sdk/v3/sugar"
1414)
1515
16- var (
17- dsn string
18- prefix string
19- )
16+ func main () {
17+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
18+ defer cancel ()
2019
21- func init () {
22- required := []string {"ydb" }
23- flagSet := flag .NewFlagSet (os .Args [0 ], flag .ExitOnError )
24- flagSet .Usage = func () {
25- out := flagSet .Output ()
26- _ , _ = fmt .Fprintf (out , "Usage:\n %s [options]\n " , os .Args [0 ])
27- _ , _ = fmt .Fprintf (out , "\n Options:\n " )
28- flagSet .PrintDefaults ()
29- }
30- flagSet .StringVar (& dsn ,
31- "ydb" , "" ,
32- "YDB connection string" ,
33- )
34- flagSet .StringVar (& prefix ,
35- "prefix" , "" ,
36- "tables prefix" ,
37- )
38- if err := flagSet .Parse (os .Args [1 :]); err != nil {
39- flagSet .Usage ()
40- os .Exit (1 )
20+ dsn , exists := os .LookupEnv ("YDB_CONNECTION_STRING" )
21+ if ! exists {
22+ panic ("YDB_CONNECTION_STRING environment variable not defined" )
4123 }
42- flagSet .Visit (func (f * flag.Flag ) {
43- for i , arg := range required {
44- if arg == f .Name {
45- required = append (required [:i ], required [i + 1 :]... )
46- }
47- }
48- })
49- if len (required ) > 0 {
50- fmt .Printf ("\n Some required options not defined: %v\n \n " , required )
51- flagSet .Usage ()
52- os .Exit (1 )
53- }
54- }
5524
56- func main () {
57- ctx , cancel := context .WithCancel (context .Background ())
58- defer cancel ()
59- opts := []ydb.Option {
25+ db , err := ydb .Open (ctx ,
26+ dsn ,
6027 environ .WithEnvironCredentials (ctx ),
61- }
62- db , err := ydb .Open (ctx , dsn , opts ... )
28+ )
6329 if err != nil {
6430 panic (fmt .Errorf ("connect error: %w" , err ))
6531 }
6632 defer func () { _ = db .Close (ctx ) }()
6733
68- prefix = path .Join (db .Name (), prefix )
34+ prefix : = path .Join (db .Name (), "native" )
6935
7036 err = sugar .RemoveRecursive (ctx , db , prefix )
7137 if err != nil {
7238 panic (err )
7339 }
7440
75- err = sugar .MakeRecursive (ctx , db , prefix )
76- if err != nil {
77- panic (err )
78- }
79-
8041 err = describeTableOptions (ctx , db .Table ())
8142 if err != nil {
8243 panic (fmt .Errorf ("describe table options error: %w" , err ))
@@ -87,9 +48,7 @@ func main() {
8748 panic (fmt .Errorf ("create tables error: %w" , err ))
8849 }
8950
90- err = describeTable (ctx , db .Table (), path .Join (
91- prefix , "series" ,
92- ))
51+ err = describeTable (ctx , db .Table (), path .Join (prefix , "series" ))
9352 if err != nil {
9453 panic (fmt .Errorf ("describe table error: %w" , err ))
9554 }
@@ -109,9 +68,7 @@ func main() {
10968 panic (fmt .Errorf ("scan query select error: %w" , err ))
11069 }
11170
112- err = readTable (ctx , db .Table (), path .Join (
113- prefix , "series" ,
114- ))
71+ err = readTable (ctx , db .Table (), path .Join (prefix , "series" ))
11572 if err != nil {
11673 panic (fmt .Errorf ("read table error: %w" , err ))
11774 }
0 commit comments