1
0
forked from MTSR/mapserver
mapserver/server/mapobjectdb/sqlite/sql.go
2019-02-09 18:05:40 +01:00

76 lines
1.6 KiB
Go

package sqlite
const migrateScript = `
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = MEMORY;
PRAGMA synchronous = OFF; --TODO: this is just ridiculously slow otherwise...
create table if not exists objects(
id integer primary key autoincrement,
x int,
y int,
z int,
posx int,
posy int,
posz int,
type varchar,
mtime bigint
);
create index if not exists objects_pos on objects(posx,posy,posz);
create index if not exists objects_pos_type on objects(posx,posy,posz,type);
create table if not exists object_attributes(
objectid integer not null,
key varchar not null,
value varchar not null,
FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE
primary key(objectid, key)
);
create index if not exists object_attributes_key_value on object_attributes(key, value);
create table if not exists settings(
key varchar primary key not null,
value varchar not null
);
`
const getMapDataPosQuery = `
select o.id, o.type, o.mtime,
o.x, o.y, o.z,
o.posx, o.posy, o.posz,
oa.key, oa.value
from objects o
left join object_attributes oa on o.id = oa.objectid
where o.type = ?
and o.posx >= ? and o.posy >= ? and o.posz >= ?
and o.posx <= ? and o.posy <= ? and o.posz <= ?
order by o.id
`
const removeMapDataQuery = `
delete from objects where posx = ? and posy = ? and posz = ?
`
const addMapDataQuery = `
insert into
objects(x,y,z,posx,posy,posz,type,mtime)
values(?, ?, ?, ?, ?, ?, ?, ?)
`
const addMapDataAttributeQuery = `
insert into
object_attributes(objectid, key, value)
values(?, ?, ?)
`
const getSettingQuery = `
select value from settings where key = ?
`
const setSettingQuery = `
insert or replace into settings(key, value)
values(?, ?)
`