-
Notifications
You must be signed in to change notification settings - Fork 6
/
postgresql.go
38 lines (32 loc) · 882 Bytes
/
postgresql.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/lib/pq" // include postgresql driver
)
const postgresqlSchema = `
CREATE TABLE IF NOT EXISTS ZwibblerDocs (
docid TEXT PRIMARY KEY,
lastAccess BIGINT,
data BYTEA
);
CREATE TABLE IF NOT EXISTS ZwibblerKeys (
docID TEXT,
name TEXT,
value TEXT,
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 NewPostgreSQLConnection(server, user, password, dbname string) DocumentDB {
psqlInfo := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable", user, password, server, dbname)
return NewSQLXConnection("postgres", psqlInfo, postgresqlSchema, 1, true)
}