diff options
Diffstat (limited to 'db')
| -rw-r--r-- | db/db.go | 42 | 
1 files changed, 42 insertions, 0 deletions
| @@ -39,6 +39,10 @@ type Model interface {  	Close() error  	GetSchemaVersion() (int, error) +	SetHostAddress(addr string) error +	GetHostAddress() (string, error) +	SetLoginPage(path string) error +	GetLoginPage() (string, error)  	CreateUser(username, password string) (User, error)  	DeleteUser(user User) error @@ -110,6 +114,10 @@ func (p *Phlox) Create(filename string) error {  		create table schema(version integer);  		insert into schema values(0); +		create table config(key string primary key, value string); +		insert into config values("hostaddress", "localhost:3333"); +		insert into config values("loginpage", ""); +  		create table users (userid integer not null primary key, username string, passwordhash string, salt string);  		create table sessions (sessionid string not null primary key, userid integer, created string, modified string, foreign key(userid) references users(userid));  		create table endpoints (endpointid integer not null primary key, name string, path string, address string); @@ -156,3 +164,37 @@ func (p *Phlox) GetSchemaVersion() (int, error) {  	return version, nil  } + + +func (p *Phlox) SetHostAddress(addr string) error { +	_, err := p.db.Exec("update config set value=? where key='hostaddress';", addr) +	return err +} + + +func (p *Phlox) GetHostAddress() (string, error) { +	row := p.db.QueryRow("select value from config where key='hostaddress';") +	var addr string +	err := row.Scan(&addr) +	if err != nil { +		return "", err +	} +	return addr, nil +} + + +func (p *Phlox) SetLoginPage(path string) error { +	_, err := p.db.Exec("update config set value=? where key='loginpage';", path) +	return err +} + + +func (p *Phlox) GetLoginPage() (string, error) { +	row := p.db.QueryRow("select value from config where key='loginpage';") +	var path string +	err := row.Scan(&path) +	if err != nil { +		return "", err +	} +	return path, nil +} | 
