|
@@ -9,6 +9,7 @@ import (
|
|
|
"flag"
|
|
"flag"
|
|
|
"reflect"
|
|
"reflect"
|
|
|
"sort"
|
|
"sort"
|
|
|
|
|
+ "speter.net/go/exp/math/dec/inf"
|
|
|
"strings"
|
|
"strings"
|
|
|
"sync"
|
|
"sync"
|
|
|
"testing"
|
|
"testing"
|
|
@@ -78,6 +79,7 @@ func TestCRUD(t *testing.T) {
|
|
|
views bigint,
|
|
views bigint,
|
|
|
protected boolean,
|
|
protected boolean,
|
|
|
modified timestamp,
|
|
modified timestamp,
|
|
|
|
|
+ rating decimal,
|
|
|
tags set<varchar>,
|
|
tags set<varchar>,
|
|
|
attachments map<varchar, text>,
|
|
attachments map<varchar, text>,
|
|
|
PRIMARY KEY (title, revid)
|
|
PRIMARY KEY (title, revid)
|
|
@@ -87,10 +89,10 @@ func TestCRUD(t *testing.T) {
|
|
|
|
|
|
|
|
for _, page := range pageTestData {
|
|
for _, page := range pageTestData {
|
|
|
if err := session.Query(`INSERT INTO page
|
|
if err := session.Query(`INSERT INTO page
|
|
|
- (title, revid, body, views, protected, modified, tags, attachments)
|
|
|
|
|
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
|
|
|
|
+ (title, revid, body, views, protected, modified, rating, tags, attachments)
|
|
|
|
|
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
page.Title, page.RevId, page.Body, page.Views, page.Protected,
|
|
page.Title, page.RevId, page.Body, page.Views, page.Protected,
|
|
|
- page.Modified, page.Tags, page.Attachments).Exec(); err != nil {
|
|
|
|
|
|
|
+ page.Modified, page.Rating, page.Tags, page.Attachments).Exec(); err != nil {
|
|
|
t.Fatal("insert:", err)
|
|
t.Fatal("insert:", err)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -106,11 +108,11 @@ func TestCRUD(t *testing.T) {
|
|
|
for _, original := range pageTestData {
|
|
for _, original := range pageTestData {
|
|
|
page := new(Page)
|
|
page := new(Page)
|
|
|
err := session.Query(`SELECT title, revid, body, views, protected, modified,
|
|
err := session.Query(`SELECT title, revid, body, views, protected, modified,
|
|
|
- tags, attachments
|
|
|
|
|
|
|
+ tags, attachments, rating
|
|
|
FROM page WHERE title = ? AND revid = ? LIMIT 1`,
|
|
FROM page WHERE title = ? AND revid = ? LIMIT 1`,
|
|
|
original.Title, original.RevId).Scan(&page.Title, &page.RevId,
|
|
original.Title, original.RevId).Scan(&page.Title, &page.RevId,
|
|
|
&page.Body, &page.Views, &page.Protected, &page.Modified, &page.Tags,
|
|
&page.Body, &page.Views, &page.Protected, &page.Modified, &page.Tags,
|
|
|
- &page.Attachments)
|
|
|
|
|
|
|
+ &page.Attachments, &page.Rating)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Error("select page:", err)
|
|
t.Error("select page:", err)
|
|
|
continue
|
|
continue
|
|
@@ -301,17 +303,21 @@ type Page struct {
|
|
|
Views int64
|
|
Views int64
|
|
|
Protected bool
|
|
Protected bool
|
|
|
Modified time.Time
|
|
Modified time.Time
|
|
|
|
|
+ Rating *inf.Dec
|
|
|
Tags []string
|
|
Tags []string
|
|
|
Attachments map[string]Attachment
|
|
Attachments map[string]Attachment
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type Attachment []byte
|
|
type Attachment []byte
|
|
|
|
|
|
|
|
|
|
+var rating, _ = inf.NewDec(0, 0).SetString("0.131")
|
|
|
|
|
+
|
|
|
var pageTestData = []*Page{
|
|
var pageTestData = []*Page{
|
|
|
&Page{
|
|
&Page{
|
|
|
Title: "Frontpage",
|
|
Title: "Frontpage",
|
|
|
RevId: TimeUUID(),
|
|
RevId: TimeUUID(),
|
|
|
Body: "Welcome to this wiki page!",
|
|
Body: "Welcome to this wiki page!",
|
|
|
|
|
+ Rating: rating,
|
|
|
Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
|
|
Modified: time.Date(2013, time.August, 13, 9, 52, 3, 0, time.UTC),
|
|
|
Tags: []string{"start", "important", "test"},
|
|
Tags: []string{"start", "important", "test"},
|
|
|
Attachments: map[string]Attachment{
|
|
Attachments: map[string]Attachment{
|