1
0
forked from MTSR/mapserver
mapserver/server/mapobjectdb/sqlite/sql.go

102 lines
2.0 KiB
Go
Raw Normal View History

2019-02-05 15:25:01 +03:00
package sqlite
const migrateScript = `
PRAGMA foreign_keys = ON;
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)
);
2019-02-05 15:42:01 +03:00
create index if not exists object_attributes_key_value on object_attributes(key, value);
2019-02-05 15:25:01 +03:00
create table if not exists tiles(
data blob,
mtime bigint,
layerid int,
x int,
y int,
zoom int,
primary key(x,y,zoom,layerid)
);
2019-02-07 10:21:19 +03:00
create table if not exists settings(
key varchar primary key not null,
value varchar not null
);
2019-02-05 15:25:01 +03:00
`
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 getTileQuery = `
select data,mtime from tiles t
where t.layerid = ?
and t.x = ?
and t.y = ?
and t.zoom = ?
`
const setTileQuery = `
insert or replace into tiles(x,y,zoom,layerid,data,mtime)
values(?, ?, ?, ?, ?, ?)
`
const removeTileQuery = `
delete from tiles
where x = ? and y = ? and zoom = ? and layerid = ?
`
2019-02-07 10:21:19 +03:00
const getSettingQuery = `
select value from settings where key = ?
`
const setSettingQuery = `
2019-02-07 11:02:15 +03:00
insert or replace into settings(key, value)
values(?, ?)
2019-02-07 10:21:19 +03:00
`