bcdata 0.10.1__tar.gz → 0.10.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bcdata-0.10.1 → bcdata-0.10.2}/CHANGES.txt +4 -0
- {bcdata-0.10.1/bcdata.egg-info → bcdata-0.10.2}/PKG-INFO +1 -1
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/__init__.py +1 -1
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/database.py +20 -17
- {bcdata-0.10.1 → bcdata-0.10.2/bcdata.egg-info}/PKG-INFO +1 -1
- {bcdata-0.10.1 → bcdata-0.10.2}/LICENSE.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/README.md +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/bc2pg.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/bcdc.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/cli.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/wcs.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/wfs.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/SOURCES.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/dependency_links.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/entry_points.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/not-zip-safe +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/requires.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/top_level.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/pyproject.toml +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/requirements.txt +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/setup.cfg +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/setup.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_bc2pg.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_bcdc.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_cli.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_wcs.py +0 -0
- {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_wfs.py +0 -0
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
3
|
|
|
4
|
-
import psycopg2
|
|
5
4
|
from geoalchemy2 import Geometry
|
|
6
|
-
from psycopg2 import sql
|
|
5
|
+
from psycopg2 import errors, sql
|
|
7
6
|
from sqlalchemy import Column, MetaData, Table, create_engine
|
|
8
7
|
from sqlalchemy.dialects.postgresql import DATE, NUMERIC, VARCHAR
|
|
9
8
|
|
|
@@ -11,18 +10,20 @@ log = logging.getLogger(__name__)
|
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class Database(object):
|
|
14
|
-
"""Wrapper around
|
|
13
|
+
"""Wrapper around sqlalchemy"""
|
|
15
14
|
|
|
16
15
|
def __init__(self, url=os.environ.get("DATABASE_URL")):
|
|
17
16
|
self.url = url
|
|
18
17
|
self.engine = create_engine(url)
|
|
19
|
-
self.conn = psycopg2.connect(url)
|
|
20
18
|
# make sure postgis is available
|
|
21
19
|
try:
|
|
22
20
|
self.query("SELECT postgis_full_version()")
|
|
23
|
-
except
|
|
24
|
-
log.error(
|
|
25
|
-
|
|
21
|
+
except errors.UndefinedFunction:
|
|
22
|
+
log.error(
|
|
23
|
+
"Cannot find PostGIS, has extension been installed on database %s ?",
|
|
24
|
+
url,
|
|
25
|
+
)
|
|
26
|
+
raise errors.UndefinedFunction
|
|
26
27
|
|
|
27
28
|
# supported oracle/wfs to postgres types
|
|
28
29
|
self.supported_types = {
|
|
@@ -56,24 +57,26 @@ class Database(object):
|
|
|
56
57
|
|
|
57
58
|
def query(self, sql, params=None):
|
|
58
59
|
"""Execute sql and return all results"""
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
conn = self.engine.raw_connection()
|
|
61
|
+
with conn.cursor() as curs:
|
|
62
|
+
curs.execute(sql, params)
|
|
63
|
+
result = curs.fetchall()
|
|
63
64
|
return result
|
|
64
65
|
|
|
65
66
|
def execute(self, sql, params=None):
|
|
66
67
|
"""Execute sql and return only whether the query was successful"""
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
conn = self.engine.raw_connection()
|
|
69
|
+
with conn.cursor() as curs:
|
|
70
|
+
result = curs.execute(sql, params)
|
|
71
|
+
conn.commit()
|
|
70
72
|
return result
|
|
71
73
|
|
|
72
74
|
def execute_many(self, sql, params):
|
|
73
75
|
"""Execute many sql"""
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
conn = self.engine.raw_connection()
|
|
77
|
+
with conn.cursor() as curs:
|
|
78
|
+
curs.executemany(sql, params)
|
|
79
|
+
conn.commit()
|
|
77
80
|
|
|
78
81
|
def create_schema(self, schema):
|
|
79
82
|
if schema not in self.schemas:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|