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 public_keys ( 21 id integer primary key autoincrement, 22 did text not null, 23 name text not null, 24 key text not null, 25 created timestamp default current_timestamp, 26 unique(did, name, key) 27 ); 28 create table if not exists repos ( 29 id integer primary key autoincrement, 30 did text not null, 31 name text not null, 32 description text not null, 33 created timestamp default current_timestamp, 34 unique(did, name) 35 ); 36 create table if not exists access_levels ( 37 id integer primary key autoincrement, 38 repo_id integer not null, 39 did text not null, 40 access text not null check (access in ('OWNER', 'WRITER')), 41 created timestamp default current_timestamp, 42 unique(repo_id, did), 43 foreign key (repo_id) references repos(id) on delete cascade 44 ); 45 `) 46 if err != nil { 47 return nil, err 48 } 49 50 return &DB{db: db}, nil 51}