+5
-4
appview/db/db.go
+5
-4
appview/db/db.go
···
21
domain text not null unique,
22
did text not null,
23
secret text not null,
24
-
created integer default (strftime('%s', 'now')),
25
-
registered integer);
26
create table if not exists public_keys (
27
id integer primary key autoincrement,
28
did text not null,
29
name text not null,
30
key text not null,
31
-
created integer default (strftime('%s', 'now')),
32
unique(did, name, key)
33
);
34
create table if not exists repos (
···
36
did text not null,
37
name text not null,
38
knot text not null,
39
-
created integer default (strftime('%s', 'now')),
40
unique(did, name, knot)
41
);
42
`)
···
21
domain text not null unique,
22
did text not null,
23
secret text not null,
24
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
25
+
registered text
26
+
);
27
create table if not exists public_keys (
28
id integer primary key autoincrement,
29
did text not null,
30
name text not null,
31
key text not null,
32
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
33
unique(did, name, key)
34
);
35
create table if not exists repos (
···
37
did text not null,
38
name text not null,
39
knot text not null,
40
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
41
unique(did, name, knot)
42
);
43
`)
+9
-7
appview/db/pubkeys.go
+9
-7
appview/db/pubkeys.go
···
21
Did string `json:"did"`
22
Key string `json:"key"`
23
Name string `json:"name"`
24
-
Created time.Time
25
}
26
27
func (p PublicKey) MarshalJSON() ([]byte, error) {
28
type Alias PublicKey
29
return json.Marshal(&struct {
30
-
Created int64 `json:"created"`
31
*Alias
32
}{
33
-
Created: p.Created.Unix(),
34
Alias: (*Alias)(&p),
35
})
36
}
···
46
47
for rows.Next() {
48
var publicKey PublicKey
49
-
var createdAt *int64
50
if err := rows.Scan(&publicKey.Key, &publicKey.Name, &publicKey.Did, &createdAt); err != nil {
51
return nil, err
52
}
53
-
publicKey.Created = time.Unix(*createdAt, 0)
54
keys = append(keys, publicKey)
55
}
56
···
72
73
for rows.Next() {
74
var publicKey PublicKey
75
-
var createdAt *int64
76
if err := rows.Scan(&publicKey.Did, &publicKey.Key, &publicKey.Name, &createdAt); err != nil {
77
return nil, err
78
}
79
-
publicKey.Created = time.Unix(*createdAt, 0)
80
keys = append(keys, publicKey)
81
}
82
···
21
Did string `json:"did"`
22
Key string `json:"key"`
23
Name string `json:"name"`
24
+
Created *time.Time
25
}
26
27
func (p PublicKey) MarshalJSON() ([]byte, error) {
28
type Alias PublicKey
29
return json.Marshal(&struct {
30
+
Created string `json:"created"`
31
*Alias
32
}{
33
+
Created: p.Created.Format(time.RFC3339),
34
Alias: (*Alias)(&p),
35
})
36
}
···
46
47
for rows.Next() {
48
var publicKey PublicKey
49
+
var createdAt string
50
if err := rows.Scan(&publicKey.Key, &publicKey.Name, &publicKey.Did, &createdAt); err != nil {
51
return nil, err
52
}
53
+
createdAtTime, _ := time.Parse(time.RFC3339, createdAt)
54
+
publicKey.Created = &createdAtTime
55
keys = append(keys, publicKey)
56
}
57
···
73
74
for rows.Next() {
75
var publicKey PublicKey
76
+
var createdAt string
77
if err := rows.Scan(&publicKey.Did, &publicKey.Key, &publicKey.Name, &createdAt); err != nil {
78
return nil, err
79
}
80
+
createdAtTime, _ := time.Parse(time.RFC3339, createdAt)
81
+
publicKey.Created = &createdAtTime
82
keys = append(keys, publicKey)
83
}
84
+9
-10
appview/db/registration.go
+9
-10
appview/db/registration.go
···
44
}
45
46
for rows.Next() {
47
-
var createdAt *int64
48
-
var registeredAt *int64
49
var registration Registration
50
err = rows.Scan(®istration.Domain, ®istration.ByDid, &createdAt, ®isteredAt)
51
52
if err != nil {
53
log.Println(err)
54
} else {
55
-
createdAtTime := time.Unix(*createdAt, 0)
56
-
57
var registeredAtTime *time.Time
58
if registeredAt != nil {
59
-
x := time.Unix(*registeredAt, 0)
60
registeredAtTime = &x
61
}
62
···
71
72
// returns registered status, did of owner, error
73
func (d *DB) RegistrationByDomain(domain string) (*Registration, error) {
74
-
var createdAt *int64
75
-
var registeredAt *int64
76
var registration Registration
77
78
err := d.db.QueryRow(`
···
88
}
89
}
90
91
-
createdAtTime := time.Unix(*createdAt, 0)
92
var registeredAtTime *time.Time
93
if registeredAt != nil {
94
-
x := time.Unix(*registeredAt, 0)
95
registeredAtTime = &x
96
}
97
···
156
func (d *DB) Register(domain string) error {
157
_, err := d.db.Exec(`
158
update registrations
159
-
set registered = strftime('%s', 'now')
160
where domain = ?;
161
`, domain)
162
···
44
}
45
46
for rows.Next() {
47
+
var createdAt *string
48
+
var registeredAt *string
49
var registration Registration
50
err = rows.Scan(®istration.Domain, ®istration.ByDid, &createdAt, ®isteredAt)
51
52
if err != nil {
53
log.Println(err)
54
} else {
55
+
createdAtTime, _ := time.Parse(time.RFC3339, *createdAt)
56
var registeredAtTime *time.Time
57
if registeredAt != nil {
58
+
x, _ := time.Parse(time.RFC3339, *registeredAt)
59
registeredAtTime = &x
60
}
61
···
70
71
// returns registered status, did of owner, error
72
func (d *DB) RegistrationByDomain(domain string) (*Registration, error) {
73
+
var createdAt *string
74
+
var registeredAt *string
75
var registration Registration
76
77
err := d.db.QueryRow(`
···
87
}
88
}
89
90
+
createdAtTime, _ := time.Parse(time.RFC3339, *createdAt)
91
var registeredAtTime *time.Time
92
if registeredAt != nil {
93
+
x, _ := time.Parse(time.RFC3339, *registeredAt)
94
registeredAtTime = &x
95
}
96
···
155
func (d *DB) Register(domain string) error {
156
_, err := d.db.Exec(`
157
update registrations
158
+
set registered = strftime('%Y-%m-%dT%H:%M:%SZ', 'now')
159
where domain = ?;
160
`, domain)
161
+10
-5
appview/db/repos.go
+10
-5
appview/db/repos.go
···
1
package db
2
3
type Repo struct {
4
Did string
5
Name string
6
Knot string
7
-
Created *int64
8
}
9
10
func (d *DB) GetAllReposByDid(did string) ([]Repo, error) {
···
18
19
for rows.Next() {
20
var repo Repo
21
-
var createdAt *int64
22
if err := rows.Scan(&repo.Did, &repo.Name, &repo.Knot, &createdAt); err != nil {
23
return nil, err
24
}
25
-
repo.Created = createdAt
26
repos = append(repos, repo)
27
}
28
···
37
var repo Repo
38
39
row := d.db.QueryRow(`select did, name, knot, created from repos where did = ? and name = ?`, did, name)
40
-
var createdAt *int64
41
if err := row.Scan(&repo.Did, &repo.Name, &repo.Knot, &createdAt); err != nil {
42
return nil, err
43
}
44
-
repo.Created = createdAt
45
46
return &repo, nil
47
}
···
1
package db
2
3
+
import "time"
4
+
5
type Repo struct {
6
Did string
7
Name string
8
Knot string
9
+
Created *time.Time
10
}
11
12
func (d *DB) GetAllReposByDid(did string) ([]Repo, error) {
···
20
21
for rows.Next() {
22
var repo Repo
23
+
var createdAt string
24
if err := rows.Scan(&repo.Did, &repo.Name, &repo.Knot, &createdAt); err != nil {
25
return nil, err
26
}
27
+
createdAtTime, _ := time.Parse(time.RFC3339, createdAt)
28
+
repo.Created = &createdAtTime
29
repos = append(repos, repo)
30
}
31
···
40
var repo Repo
41
42
row := d.db.QueryRow(`select did, name, knot, created from repos where did = ? and name = ?`, did, name)
43
+
44
+
var createdAt string
45
if err := row.Scan(&repo.Did, &repo.Name, &repo.Knot, &createdAt); err != nil {
46
return nil, err
47
}
48
+
createdAtTime, _ := time.Parse(time.RFC3339, createdAt)
49
+
repo.Created = &createdAtTime
50
51
return &repo, nil
52
}
+1
appview/state/middleware.go
+1
appview/state/middleware.go
+2
-2
knotserver/db/init.go
+2
-2
knotserver/db/init.go
···
25
id integer primary key autoincrement,
26
did text not null,
27
key text not null,
28
-
created timestamp default current_timestamp,
29
unique(did, key),
30
foreign key (did) references known_dids(did) on delete cascade
31
);
···
35
did text not null,
36
name text not null,
37
description text not null,
38
-
created timestamp default current_timestamp,
39
unique(did, name)
40
);
41
···
25
id integer primary key autoincrement,
26
did text not null,
27
key text not null,
28
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
29
unique(did, key),
30
foreign key (did) references known_dids(did) on delete cascade
31
);
···
35
did text not null,
36
name text not null,
37
description text not null,
38
+
created text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
39
unique(did, name)
40
);
41
+1
-1
knotserver/db/pubkeys.go
+1
-1
knotserver/db/pubkeys.go