-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
48 lines (41 loc) · 891 Bytes
/
main.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
package main
import (
"fmt"
"time"
sql "github.com/FloatTech/sqlite"
)
type article struct {
ID int64 `db:"id"`
Title string `db:"title"`
Author string `db:"author"`
CreateTime string `db:"createTime"`
Content string `db:"content"`
}
var db = &sql.Sqlite{}
// 暂时随机选择一个小作文
func getArticleByKeyword(keyword string) (a article) {
_ = db.Find("main", &a, "where content LIKE '%"+keyword+"%'")
return
}
func getRandomArticle() (a article) {
_ = db.Pick("main", &a)
return
}
func main() {
db.DBPath = "code/third/小作文.db"
err := db.Open(time.Hour * 24)
if err != nil {
fmt.Println(err)
}
err = db.Create("main", &article{})
if err != nil {
fmt.Println(err)
}
n, err := db.Count("main")
if err != nil {
fmt.Println(err)
}
fmt.Println("一共有", n, "条记录")
a := getRandomArticle()
fmt.Printf("%+v\n", a)
}