diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fac628 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/data/ \ No newline at end of file diff --git a/examples/cities/data/cities.csv b/examples/cities/data/cities.csv new file mode 100644 index 0000000..dbf4c45 --- /dev/null +++ b/examples/cities/data/cities.csv @@ -0,0 +1,35 @@ +rectype,ctype,regiokey,ckey,name,area,inhabitants,zipcode,long,lat +40,42,08111,08111,"Stuttgart, Stadtkreis",,,,, +50,50,081110000,08111,"Stuttgart, Landeshauptstadt",,,,, +60,62,081110000000,08111000,"Stuttgart, Landeshauptstadt",207.33,634830,70173,9.177734,48.775817 +40,44,08115,08115,Böblingen,,,,, +50,50,081150003,08115,"Böblingen, Stadt",,,,, +60,67,081150003003,08115003,"Böblingen, Stadt",39.04,50155,71032,9.009663,48.685296 +50,50,081150052,08115,Weissach,,,,, +60,64,081150052052,08115052,Weissach,22.19,7519,71287,8.927545,48.846812 +50,56,081155001,08115,GVV Aidlingen/Grafenau,,,,, +60,64,081155001001,08115001,Aidlingen,26.56,9024,71134,8.896991,48.677969 +60,64,081155001054,08115054,Grafenau,13.04,6747,71120,8.91395,48.711098 +50,56,081155002,08115,GVV Gärtringen/Ehningen,,,,, +60,64,081155002013,08115013,Ehningen,17.81,9193,71139,8.940525,48.65926 +60,64,081155002015,08115015,Gärtringen,20.21,12417,71116,8.901692,48.641924 +50,54,081155003,08115,VVG der Stadt Herrenberg,,,,, +60,64,081155003010,08115010,Deckenpfronn,11.41,3329,75392,8.822512,48.65171 +60,67,081155003021,08115021,"Herrenberg, Stadt",65.7,31545,71083,8.867369,48.595705 +60,64,081155003037,08115037,Nufringen,10.04,5872,71154,8.888193,48.622489 +40,44,08116,08116,Esslingen,,,,, +50,50,081160015,08116,Denkendorf,,,,, +60,64,081160015015,08116015,Denkendorf,13.05,11240,73770,9.31755,48.694154 +50,50,081160019,08116,"Esslingen am Neckar, Stadt",,,,, +60,67,081160019019,08116019,"Esslingen am Neckar, Stadt",46.43,93542,73728,9.309565,48.741347 +50,54,081165001,08116,VVG der Stadt Kirchheim unter Teck,,,,, +60,64,081165001016,08116016,Dettingen unter Teck,15.13,6142,73265,9.45268,48.61725 +60,67,081165001033,08116033,"Kirchheim unter Teck, Stadt",40.47,40523,73230,9.453784,48.646093 +60,64,081165001048,08116048,Notzingen,7.7,3687,73274,9.462005,48.671109 +50,56,081165003,08116,GVV Neckartenzlingen,,,,, +60,64,081165003005,08116005,Altdorf,3.24,1700,72655,9.271505,48.594688 +60,64,081165003006,08116006,Altenriet,3.35,1921,72657,9.221764,48.591482 +60,64,081165003008,08116008,Bempflingen,6.27,3485,72658,9.26546,48.573217 +60,64,081165003041,08116041,Neckartailfingen,8.23,3846,72666,9.262633,48.61255 +60,64,081165003042,08116042,Neckartenzlingen,9.03,6498,72654,9.233903,48.590722 +60,64,081165003063,08116063,Schlaitdorf,7.31,1931,72667,9.222445,48.604296 diff --git a/pgsql/fshow.sql b/pgsql/fshow.sql new file mode 100644 index 0000000..224192c --- /dev/null +++ b/pgsql/fshow.sql @@ -0,0 +1,16 @@ + +create or replace function show(type smallint, id bigint) returns text as $$ +declare tname text := (select dtname from datatypes as dt where dt.id = type); +begin + case tname + when 'node' then + return ( + select ns.prefix || ':' || n.name + from nodes n + join namespaces ns on ns.id = n.namespace + where n.id = show.id + ); + else return tname; + end case; +end; +$$ language plpgsql; diff --git a/pgsql/init.sql b/pgsql/init.sql index 04483b6..72faa4c 100644 --- a/pgsql/init.sql +++ b/pgsql/init.sql @@ -75,15 +75,17 @@ INSERT INTO nodes (namespace, name) VALUES -- type -> Property; Property, Class -> Class INSERT INTO triples (stype, svalue, predicate, otype, ovalue, creation) VALUES - (2, 1, 2, 2, 2, 1), - (2, 2, 2, 2, 3, 1), - (2, 3, 2, 2, 3, 1); + (2, 1, 1, 2, 2, 1), + (2, 2, 1, 2, 3, 1), + (2, 3, 1, 2, 3, 1); -- indexes CREATE INDEX idx_iri ON namespaces USING btree (iri); CREATE INDEX idx_prefix ON namespaces USING btree (prefix); +CREATE INDEX idx_dtname ON datatypes USING btree (dtname); + CREATE INDEX idx_node_name ON nodes USING btree (namespace, name); CREATE INDEX fki_stype ON triples USING btree (stype); diff --git a/pgsql/qtriples.sql b/pgsql/qtriples.sql new file mode 100644 index 0000000..f7d9423 --- /dev/null +++ b/pgsql/qtriples.sql @@ -0,0 +1,4 @@ + +select id, stext, ptext, otext, ts + from vtriples + \ No newline at end of file diff --git a/pgsql/vtriples.sql b/pgsql/vtriples.sql new file mode 100644 index 0000000..7b872b1 --- /dev/null +++ b/pgsql/vtriples.sql @@ -0,0 +1,12 @@ + +create or replace view vtriples as +select triples.id, + stype, svalue, show(stype, svalue) as stext, + predicate, show(dt.id, predicate) as ptext, + otype, ovalue, show(otype, ovalue) as otext, + events.tstamp as ts + from triples, datatypes dt, events + where dtname = 'node' + and events.id = creation + and deletion is null +;