-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.go
66 lines (50 loc) · 1.06 KB
/
database.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"log"
"os"
)
type Database interface {
InsertBatch(batch [][]any) error
Migrate() error
}
// makes use of std lib to output to file
type FlatFileDatabase struct {
//str fmt eg "value=%s value2=%s intval=%d"
format string
logger *log.Logger
}
func NewFlatFileDatabase(path string, format string) *FlatFileDatabase {
file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatal(err)
}
//dont think it should be 0
logger := log.New(file, "", 0)
// example_fmt := "value1=%s value2=%s"
return &FlatFileDatabase{
format: format,
logger: logger,
}
}
func (db *FlatFileDatabase) InsertBatch(batch [][]any) error {
str := ""
for _, elem := range batch {
str += fmt.Sprintf(db.format+"\n", elem...)
}
db.logger.Print(str)
return nil
}
func (db FlatFileDatabase) Migrate() error {
return nil
}
type SQLite3 struct{}
func NewSQLite3() *SQLite3 {
return &SQLite3{}
}
func (db SQLite3) InsertBatch(batch []any) error {
return nil
}
func (db SQLite3) Migrate() error {
return nil
}