settings table

This commit is contained in:
NatureFreshMilk 2019-02-07 08:21:19 +01:00
parent 7b5b88a75e
commit 1ee78ee106
3 changed files with 47 additions and 0 deletions

View File

@ -80,4 +80,8 @@ type DBAccessor interface {
GetTile(pos *coords.TileCoords) (*Tile, error)
SetTile(tile *Tile) error
RemoveTile(pos *coords.TileCoords) error
//Settings
GetSetting(key string, defaultvalue string) (string, error)
SetSetting(key string, value string) error
}

View File

@ -0,0 +1,30 @@
package sqlite
func (db *Sqlite3Accessor) GetSetting(key string, defaultvalue string) (string, error) {
rows, err := db.db.Query(getSettingQuery, key)
if err != nil {
return "", err
}
defer rows.Close()
value := defaultvalue
if rows.Next() {
err = rows.Scan(&value)
if err != nil {
return "", err
}
}
return value, nil
}
func (db *Sqlite3Accessor) SetSetting(key string, value string) error {
_, err := db.db.Exec(setSettingQuery, value, key)
return err
}

View File

@ -37,6 +37,11 @@ create table if not exists tiles(
zoom int,
primary key(x,y,zoom,layerid)
);
create table if not exists settings(
key varchar primary key not null,
value varchar not null
);
`
const getMapDataPosQuery = `
@ -85,3 +90,11 @@ const removeTileQuery = `
delete from tiles
where x = ? and y = ? and zoom = ? and layerid = ?
`
const getSettingQuery = `
select value from settings where key = ?
`
const setSettingQuery = `
update settings set value = ? where key = ?
`