MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / main

Function main

client/_example/simple.go:28–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func main() {
29 log.SetLevel(log.InfoLevel)
30 var dsn string
31
32 flag.StringVar(&dsn, "dsn", "", "Database url")
33 flag.Parse()
34
35 // If your CovenantSQL config.yaml is not in ~/.cql/config.yaml
36 // Uncomment and edit following code
37 /*
38 config := "/data/myconfig/config.yaml"
39 password := "mypassword"
40 err := client.Init(config, []byte(password))
41 if err != nil {
42 log.Fatal(err)
43 }
44 */
45
46 db, err := sql.Open("covenantsql", dsn)
47 if err != nil {
48 log.Fatal(err)
49 }
50 defer db.Close()
51
52 _, err = db.Exec("DROP TABLE IF EXISTS testSimple;")
53 if err != nil {
54 log.Fatal(err)
55 }
56
57 _, err = db.Exec("CREATE TABLE testSimple ( indexedColumn, nonIndexedColumn );")
58 if err != nil {
59 log.Fatal(err)
60 }
61
62 _, err = db.Exec("CREATE INDEX testIndexedColumn ON testSimple ( indexedColumn );")
63 if err != nil {
64 log.Fatal(err)
65 }
66
67 _, err = db.Exec("INSERT INTO testSimple VALUES(?, ?);", 4, 400)
68 if err != nil {
69 log.Fatal(err)
70 }
71
72 row := db.QueryRow("SELECT nonIndexedColumn FROM testSimple LIMIT 1;")
73
74 var result int
75 err = row.Scan(&result)
76 if err != nil {
77 log.Fatal(err)
78 }
79 fmt.Printf("SELECT nonIndexedColumn FROM testSimple LIMIT 1; result %d\n", result)
80
81}

Callers

nothing calls this directly

Calls 8

SetLevelFunction · 0.92
FatalFunction · 0.92
QueryRowMethod · 0.80
CloseMethod · 0.65
ExecMethod · 0.65
OpenMethod · 0.45
ScanMethod · 0.45
PrintfMethod · 0.45

Tested by

no test coverage detected