1
0
forked from MTSR/mapserver
mapserver/server/db/postgres/sql.go

53 lines
996 B
Go
Raw Normal View History

2019-02-05 15:13:34 +03:00
package postgres
const migrateScript = `
2019-02-06 18:10:18 +03:00
alter table blocks add column mtime bigint not null default 0;
create index BLOCKS_TIME on blocks(mtime);
create or replace function on_blocks_change() returns trigger as
$BODY$
BEGIN
NEW.mtime = floor(EXTRACT(EPOCH from now()) * 1000);
return NEW;
END;
$BODY$
LANGUAGE plpgsql;
create trigger blocks_update
before insert or update
on blocks
for each row
execute procedure on_blocks_change();
2019-02-05 15:13:34 +03:00
`
const getBlocksByMtimeQuery = `
2019-02-06 18:10:18 +03:00
select posx,posy,posz,data,mtime
2019-02-05 15:13:34 +03:00
from blocks b
where b.mtime > ?
order by b.mtime asc
limit ?
`
const getLastBlockQuery = `
2019-02-06 18:10:18 +03:00
select posx,posy,posz,data,mtime
2019-02-05 15:13:34 +03:00
from blocks b
where b.mtime = 0
2019-02-06 18:10:18 +03:00
and b.posx >= ?
and b.posy >= ?
and b.posz >= ?
order by b.posx asc, b.posy asc, b.posz asc, b.mtime asc
2019-02-05 15:13:34 +03:00
limit ?
`
const countBlocksQuery = `
select count(*) from blocks b where b.mtime >= ? and b.mtime <= ?
`
const getBlockQuery = `
2019-02-06 18:10:18 +03:00
select pos,data,mtime from blocks b
where b.posx = ?
and b.posy = ?
and b.posz = ?
2019-02-05 15:13:34 +03:00
`