Skip to content

Commit

Permalink
Switch flex config files from hstore to jsonb
Browse files Browse the repository at this point in the history
The jsonb data type is built into PostgreSQL, no hstore extension is
needed. It is more flexible and there are more functions to extract
data from it.
  • Loading branch information
joto committed May 14, 2021
1 parent 674a753 commit 6cd1560
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions flex-config/attributes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local srid = 4326
local tables = {}

tables.points = osm2pgsql.define_node_table('points', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
Expand All @@ -21,7 +21,7 @@ tables.points = osm2pgsql.define_node_table('points', {
})

tables.lines = osm2pgsql.define_way_table('lines', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring', projection = srid },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
Expand All @@ -31,7 +31,7 @@ tables.lines = osm2pgsql.define_way_table('lines', {
})

tables.relations = osm2pgsql.define_relation_table('relations', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'version', type = 'int' },
{ column = 'changeset', type = 'int' },
{ column = 'created', type = 'timestamp' },
Expand Down
4 changes: 2 additions & 2 deletions flex-config/data-types.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Look at and understand "simple.lua" first, before looking
-- at this file. This file demonstrates some column data type options.

Expand All @@ -19,7 +19,7 @@ local highways = osm2pgsql.define_way_table('highways', {

-- type "bool" is special, see below
{ column = 'lit', type = 'bool' },
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' }, -- also available: 'json', 'hstore'

-- an PostgreSQL array type, not specially handled by osm2pgsql, see below
{ column = 'nodes', type = 'int8[]' },
Expand Down
12 changes: 6 additions & 6 deletions flex-config/generic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@

-- This is a generic configuration that is a good starting point for
-- real-world projects. Data is split into tables according to geometry type
-- and most tags are stored in hstore columns.
-- and most tags are stored in jsonb columns.

-- Set this to the projection you want to use
local srid = 3857

local tables = {}

tables.points = osm2pgsql.define_node_table('points', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point', projection = srid },
})

tables.lines = osm2pgsql.define_way_table('lines', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring', projection = srid },
})

tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry', projection = srid },
{ column = 'area', type = 'area' },
})

tables.routes = osm2pgsql.define_relation_table('routes', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'multilinestring', projection = srid },
})

tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'multilinestring', projection = srid },
})

Expand Down
10 changes: 5 additions & 5 deletions flex-config/geometries.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Look at and understand "simple.lua" first, before looking
-- at this file. This file will show some options around geometry processing.
-- After you have understood this file, go on to "data-types.lua".

local tables = {}

tables.pois = osm2pgsql.define_node_table('pois', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Create a geometry column for point geometries. The geometry will be
-- in web mercator, EPSG 3857.
{ column = 'geom', type = 'point' },
})

tables.ways = osm2pgsql.define_way_table('ways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Create a geometry column for linestring geometries. The geometry will
-- be in latlong (WGS84), EPSG 4326.
{ column = 'geom', type = 'linestring', projection = 4326 },
})

tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
-- The 'area' type is used to store the calculated area of a polygon
-- feature. This can be used in style sheets to only render larger polygons
Expand All @@ -34,7 +34,7 @@ tables.polygons = osm2pgsql.define_area_table('polygons', {

tables.boundaries = osm2pgsql.define_relation_table('boundaries', {
{ column = 'type', type = 'text' },
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- Boundaries will be stitched together from relation members into long
-- linestrings. This is a multilinestring column because sometimes the
-- boundaries are not contiguous.
Expand Down
4 changes: 2 additions & 2 deletions flex-config/route-relations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
local tables = {}

tables.highways = osm2pgsql.define_way_table('highways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'rel_refs', type = 'text' }, -- for the refs from the relations
{ column = 'rel_ids', type = 'int8[]' }, -- array with integers (for relation IDs)
{ column = 'geom', type = 'linestring' },
})

-- Tables don't have to have a geometry column
tables.routes = osm2pgsql.define_relation_table('routes', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
})

-- This will be used to store information about relations queryable by member
Expand Down
10 changes: 5 additions & 5 deletions flex-config/simple.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- This config example file is released into the Public Domain.

-- This is a very simple Lua config for the Flex Backend not intended for
-- This is a very simple Lua config for the Flex output not intended for
-- real-world use. Use it do understand the basic principles of the
-- configuration. After reading and understanding this, have a look at
-- "geometries.lua".
Expand All @@ -24,7 +24,7 @@ local tables = {}
-- "append" mode, osm2pgsql will automatically update this table using the node
-- ids.
tables.pois = osm2pgsql.define_node_table('pois', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'point' }, -- will be something like `GEOMETRY(Point, 4326)` in SQL
})

Expand All @@ -40,7 +40,7 @@ tables.restaurants = osm2pgsql.define_node_table('restaurants', {
-- contain a "way_id" column. When running in "append" mode, osm2pgsql will
-- automatically update this table using the way ids.
tables.ways = osm2pgsql.define_way_table('ways', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'linestring' },
})

Expand All @@ -50,7 +50,7 @@ tables.ways = osm2pgsql.define_way_table('ways', {
-- running in "append" mode, osm2pgsql will automatically update this table
-- using the way/relation ids.
tables.polygons = osm2pgsql.define_area_table('polygons', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
-- The type of the `geom` column is `geometry`, because we need to store
-- polygons AND multipolygons
{ column = 'geom', type = 'geometry' },
Expand Down Expand Up @@ -95,7 +95,7 @@ function osm2pgsql.process_node(object)
})
else
tables.pois:add_row({
-- We know `tags` is of type `hstore` so this will do the
-- We know `tags` is of type `jsonb` so this will do the
-- right thing.
tags = object.tags
})
Expand Down
4 changes: 2 additions & 2 deletions flex-config/unitable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ local dtable = osm2pgsql.define_table{
-- "osm_type CHAR(1)" for the type of object: N(ode), W(way), R(relation)
ids = { type = 'any', id_column = 'osm_id', type_column = 'osm_type' },
columns = {
{ column = 'attrs', type = 'hstore' },
{ column = 'tags', type = 'hstore' },
{ column = 'attrs', type = 'jsonb' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
}
}
Expand Down
2 changes: 1 addition & 1 deletion flex-config/with-schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-- your database (created with something like `CREATE SCHEMA myschema;`).

local dtable = osm2pgsql.define_way_table('data', {
{ column = 'tags', type = 'hstore' },
{ column = 'tags', type = 'jsonb' },
{ column = 'geom', type = 'geometry' },
}, { schema = 'myschema' })

Expand Down

0 comments on commit 6cd1560

Please sign in to comment.