settings table
This commit is contained in:
parent
7b5b88a75e
commit
1ee78ee106
@ -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
|
||||
}
|
||||
|
30
server/mapobjectdb/sqlite/settings.go
Normal file
30
server/mapobjectdb/sqlite/settings.go
Normal 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
|
||||
}
|
@ -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 = ?
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user