-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmariadb.go
38 lines (32 loc) · 928 Bytes
/
mariadb.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
package zwibserve
import (
"fmt"
_ "github.com/go-sql-driver/mysql" // include mysql driver
)
const mariadbSchema = `
CREATE TABLE IF NOT EXISTS ZwibblerDocs (
docID TEXT PRIMARY KEY,
lastAccess BIGINT,
data LONGBLOB
);
CREATE TABLE IF NOT EXISTS ZwibblerKeys (
docID TEXT,
name TEXT,
value MEDIUMTEXT,
version INT,
UNIQUE(docID, name),
FOREIGN KEY (docID) REFERENCES ZwibblerDocs(docid) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS ZwibblerTokens (
tokenID TEXT UNIQUE,
docID TEXT,
userID TEXT,
permissions TEXT,
expiration BIGINT
);
CREATE INDEX IF NOT EXISTS ZwibblerTokenUserIndex ON ZwibblerTokens(userID);
`
func NewMariaDBConnection(server, user, password, dbname string) DocumentDB {
mariaInfo := fmt.Sprintf("%s:%s@(%s)/%s?multiStatements=true", user, password, server, dbname)
return NewSQLXConnection("mysql", mariaInfo, mariadbSchema, 1, false)
}