@@ -6,71 +6,71 @@ defmodule Geo.PostGIS.Test do
66 username: "postgres" , database: "geo_postgrex_test" ,
77 extensions: [ { Geo.PostGIS.Extension , library: Geo } ] ]
88
9- { :ok , pid } = Postgrex.Connection . start_link ( opts )
10- { :ok , _result } = Postgrex.Connection . query ( pid , "DROP TABLE IF EXISTS text_test, point_test, linestring_test, polygon_test, multipoint_test, multilinestring_test, multipolygon_test, geometrycollection_test" , [ ] )
9+ { :ok , pid } = Postgrex . start_link ( opts )
10+ { :ok , _result } = Postgrex . query ( pid , "DROP TABLE IF EXISTS text_test, point_test, linestring_test, polygon_test, multipoint_test, multilinestring_test, multipolygon_test, geometrycollection_test" , [ ] )
1111 { :ok , [ pid: pid ] }
1212 end
1313
1414 test "insert point" , context do
1515 pid = context [ :pid ]
1616 geo = % Geo.Point { coordinates: { 30 , - 90 } , srid: 4326 }
17- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE point_test (id int, geom geometry(Point, 4326))" , [ ] )
18- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO point_test VALUES ($1, $2)" , [ 42 , geo ] )
19- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM point_test" , [ ] )
17+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE point_test (id int, geom geometry(Point, 4326))" , [ ] )
18+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO point_test VALUES ($1, $2)" , [ 42 , geo ] )
19+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM point_test" , [ ] )
2020 assert ( result . rows == [ [ 42 , geo ] ] )
2121 end
2222
2323 test "insert with text column" , context do
2424 pid = context [ :pid ]
2525 geo = % Geo.Point { coordinates: { 30 , - 90 } , srid: 4326 }
26- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE text_test (id int, t text, geom geometry(Point, 4326))" , [ ] )
27- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO text_test (id, t, geom) VALUES ($1, $2, $3)" , [ 42 , "test" , geo ] )
28- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT id, t, geom FROM text_test" , [ ] )
26+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE text_test (id int, t text, geom geometry(Point, 4326))" , [ ] )
27+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO text_test (id, t, geom) VALUES ($1, $2, $3)" , [ 42 , "test" , geo ] )
28+ { :ok , result } = Postgrex . query ( pid , "SELECT id, t, geom FROM text_test" , [ ] )
2929 assert ( result . rows == [ [ 42 , "test" , geo ] ] )
3030 end
3131
3232 test "insert linestring" , context do
3333 pid = context [ :pid ]
3434 geo = % Geo.LineString { srid: 4326 , coordinates: [ { 30 , 10 } , { 10 , 30 } , { 40 , 40 } ] }
35- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE linestring_test (id int, geom geometry(Linestring, 4326))" , [ ] )
36- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO linestring_test VALUES ($1, $2)" , [ 42 , geo ] )
37- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM linestring_test" , [ ] )
35+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE linestring_test (id int, geom geometry(Linestring, 4326))" , [ ] )
36+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO linestring_test VALUES ($1, $2)" , [ 42 , geo ] )
37+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM linestring_test" , [ ] )
3838 assert ( result . rows == [ [ 42 , geo ] ] )
3939 end
4040
4141 test "insert polygon" , context do
4242 pid = context [ :pid ]
4343 geo = % Geo.Polygon { coordinates: [ [ { 35 , 10 } , { 45 , 45 } , { 15 , 40 } , { 10 , 20 } , { 35 , 10 } ] , [ { 20 , 30 } , { 35 , 35 } , { 30 , 20 } , { 20 , 30 } ] ] , srid: 4326 }
44- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE polygon_test (id int, geom geometry(Polygon, 4326))" , [ ] )
45- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO polygon_test VALUES ($1, $2)" , [ 42 , geo ] )
46- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM polygon_test" , [ ] )
44+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE polygon_test (id int, geom geometry(Polygon, 4326))" , [ ] )
45+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO polygon_test VALUES ($1, $2)" , [ 42 , geo ] )
46+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM polygon_test" , [ ] )
4747 assert ( result . rows == [ [ 42 , geo ] ] )
4848 end
4949
5050 test "insert mulitpoint" , context do
5151 pid = context [ :pid ]
5252 geo = % Geo.MultiPoint { coordinates: [ { 0 , 0 } , { 20 , 20 } , { 60 , 60 } ] , srid: 4326 }
53- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE multipoint_test (id int, geom geometry(MultiPoint, 4326))" , [ ] )
54- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO multipoint_test VALUES ($1, $2)" , [ 42 , geo ] )
55- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM multipoint_test" , [ ] )
53+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE multipoint_test (id int, geom geometry(MultiPoint, 4326))" , [ ] )
54+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO multipoint_test VALUES ($1, $2)" , [ 42 , geo ] )
55+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM multipoint_test" , [ ] )
5656 assert ( result . rows == [ [ 42 , geo ] ] )
5757 end
5858
5959 test "insert mulitlinestring" , context do
6060 pid = context [ :pid ]
6161 geo = % Geo.MultiLineString { coordinates: [ [ { 10 , 10 } , { 20 , 20 } , { 10 , 40 } ] , [ { 40 , 40 } , { 30 , 30 } , { 40 , 20 } , { 30 , 10 } ] ] , srid: 4326 }
62- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE multilinestring_test (id int, geom geometry(MultiLinestring, 4326))" , [ ] )
63- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO multilinestring_test VALUES ($1, $2)" , [ 42 , geo ] )
64- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM multilinestring_test" , [ ] )
62+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE multilinestring_test (id int, geom geometry(MultiLinestring, 4326))" , [ ] )
63+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO multilinestring_test VALUES ($1, $2)" , [ 42 , geo ] )
64+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM multilinestring_test" , [ ] )
6565 assert ( result . rows == [ [ 42 , geo ] ] )
6666 end
6767
6868 test "insert mulitpolygon" , context do
6969 pid = context [ :pid ]
7070 geo = % Geo.MultiPolygon { coordinates: [ [ [ { 40 , 40 } , { 20 , 45 } , { 45 , 30 } , { 40 , 40 } ] ] , [ [ { 20 , 35 } , { 10 , 30 } , { 10 , 10 } , { 30 , 5 } , { 45 , 20 } , { 20 , 35 } ] , [ { 30 , 20 } , { 20 , 15 } , { 20 , 25 } , { 30 , 20 } ] ] ] , srid: 4326 }
71- { :ok , _ } = Postgrex.Connection . query ( pid , "CREATE TABLE multipolygon_test (id int, geom geometry(MultiPolygon, 4326))" , [ ] )
72- { :ok , _ } = Postgrex.Connection . query ( pid , "INSERT INTO multipolygon_test VALUES ($1, $2)" , [ 42 , geo ] )
73- { :ok , result } = Postgrex.Connection . query ( pid , "SELECT * FROM multipolygon_test" , [ ] )
71+ { :ok , _ } = Postgrex . query ( pid , "CREATE TABLE multipolygon_test (id int, geom geometry(MultiPolygon, 4326))" , [ ] )
72+ { :ok , _ } = Postgrex . query ( pid , "INSERT INTO multipolygon_test VALUES ($1, $2)" , [ 42 , geo ] )
73+ { :ok , result } = Postgrex . query ( pid , "SELECT * FROM multipolygon_test" , [ ] )
7474 assert ( result . rows == [ [ 42 , geo ] ] )
7575 end
7676end
0 commit comments