-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbeval.go
61 lines (47 loc) · 1.18 KB
/
dbeval.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
package dbeval
import (
_ "embed"
"time"
"github.com/uptrace/bun"
)
type Author struct {
bun.BaseModel `bun:"table:authors,alias:au" xorm:"-"`
ID int64 `db:"id" gorm:"PRIMARY_KEY" xorm:"'id'" bun:"id,pk,autoincrement"`
Name string `db:"name"`
}
func (Author) TableName() string {
return "authors"
}
type Article struct {
bun.BaseModel `bun:"table:articles,alias:ar" xorm:"-"`
ID int64 `db:"id" gorm:"PRIMARY_KEY" xorm:"'id'" bun:"id,pk,autoincrement"`
Title string `db:"title"`
Body string `db:"body"`
PublishedAt time.Time `db:"published_at"`
}
func (Article) TableName() string {
return "articles"
}
type Implementation interface {
Connect(string, time.Duration, int, int)
CreateDatabase()
DropDatabase()
CreateSchema()
InsertAuthors([]*Author)
InsertArticles([]*Article)
FindAuthorByID(int64) *Author
FindAuthorsByName(string) []*Author
RecentArticles(int) []*Article
}
const testDatabaseName = "dbeval_db"
const createdb = `
CREATE DATABASE ` + testDatabaseName + `;`
const dropdb = `
DROP DATABASE IF EXISTS ` + testDatabaseName + `;`
//go:embed schema.sql
var schema string
func check(err error) {
if err != nil {
panic(err)
}
}