this repo has no description
1package db 2 3import ( 4 "database/sql" 5 6 _ "github.com/mattn/go-sqlite3" 7) 8 9type DB struct { 10 db *sql.DB 11} 12 13func Setup(dbPath string) (*DB, error) { 14 db, err := sql.Open("sqlite3", dbPath) 15 if err != nil { 16 return nil, err 17 } 18 19 _, err = db.Exec(` 20 create table if not exists known_dids ( 21 did text primary key 22 ); 23 create table if not exists public_keys ( 24 id integer primary key autoincrement, 25 did text not null, 26 key text not null, 27 created timestamp default current_timestamp, 28 unique(did, key), 29 foreign key (did) references known_dids(did) on delete cascade 30 ); 31 32 create table if not exists repos ( 33 id integer primary key autoincrement, 34 did text not null, 35 name text not null, 36 description text not null, 37 created timestamp default current_timestamp, 38 unique(did, name) 39 ); 40 create table if not exists access_levels ( 41 id integer primary key autoincrement, 42 repo_id integer not null, 43 did text not null, 44 access text not null check (access in ('OWNER', 'WRITER')), 45 created timestamp default current_timestamp, 46 unique(repo_id, did), 47 foreign key (repo_id) references repos(id) on delete cascade 48 ); 49 `) 50 if err != nil { 51 return nil, err 52 } 53 54 return &DB{db: db}, nil 55}