-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdibbi.go
More file actions
32 lines (30 loc) · 750 Bytes
/
dibbi.go
File metadata and controls
32 lines (30 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Package dibbi contains functions to manipulate a dibbi instance.
package dibbi
// Query the given database with the provided input.
func Query(query string, db *Database) (result *Results, error error) {
ast, err := parse(query)
if err != nil {
return nil, err
}
for _, stmt := range ast.Statements {
switch stmt.statementType {
case CreateTableType:
err = (*db).CreateTable(ast.Statements[0].createTableStatement)
if err != nil {
return nil, err
}
case InsertType:
err = (*db).Insert(stmt.insertStatement)
if err != nil {
return nil, err
}
case SelectType:
results, err := (*db).Select(stmt.selectStatement)
if err != nil {
return nil, err
}
return results, nil
}
}
return nil, nil
}