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.
Files changed (27) hide show
  1. {bcdata-0.10.1 → bcdata-0.10.2}/CHANGES.txt +4 -0
  2. {bcdata-0.10.1/bcdata.egg-info → bcdata-0.10.2}/PKG-INFO +1 -1
  3. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/__init__.py +1 -1
  4. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/database.py +20 -17
  5. {bcdata-0.10.1 → bcdata-0.10.2/bcdata.egg-info}/PKG-INFO +1 -1
  6. {bcdata-0.10.1 → bcdata-0.10.2}/LICENSE.txt +0 -0
  7. {bcdata-0.10.1 → bcdata-0.10.2}/README.md +0 -0
  8. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/bc2pg.py +0 -0
  9. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/bcdc.py +0 -0
  10. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/cli.py +0 -0
  11. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/wcs.py +0 -0
  12. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata/wfs.py +0 -0
  13. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/SOURCES.txt +0 -0
  14. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/dependency_links.txt +0 -0
  15. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/entry_points.txt +0 -0
  16. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/not-zip-safe +0 -0
  17. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/requires.txt +0 -0
  18. {bcdata-0.10.1 → bcdata-0.10.2}/bcdata.egg-info/top_level.txt +0 -0
  19. {bcdata-0.10.1 → bcdata-0.10.2}/pyproject.toml +0 -0
  20. {bcdata-0.10.1 → bcdata-0.10.2}/requirements.txt +0 -0
  21. {bcdata-0.10.1 → bcdata-0.10.2}/setup.cfg +0 -0
  22. {bcdata-0.10.1 → bcdata-0.10.2}/setup.py +0 -0
  23. {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_bc2pg.py +0 -0
  24. {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_bcdc.py +0 -0
  25. {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_cli.py +0 -0
  26. {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_wcs.py +0 -0
  27. {bcdata-0.10.1 → bcdata-0.10.2}/tests/test_wfs.py +0 -0
@@ -1,6 +1,10 @@
1
1
  Changes
2
2
  =======
3
3
 
4
+ 0.10.2 (2024-03-01)
5
+ ------------------
6
+ - improve connection management for better stability (#171)
7
+
4
8
  0.10.1 (2024-02-19)
5
9
  ------------------
6
10
  - check that table to be refreshed exists when using bc2pg --refresh (#167)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.10.1
3
+ Version: 0.10.2
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
@@ -15,4 +15,4 @@ PRIMARY_KEY_DB_URL = (
15
15
  "https://raw.githubusercontent.com/smnorris/bcdata/main/data/primary_keys.json"
16
16
  )
17
17
 
18
- __version__ = "0.10.1"
18
+ __version__ = "0.10.2"
@@ -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 psycopg2 and sqlachemy"""
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 psycopg2.errors.UndefinedFunction:
24
- log.error("Cannot find PostGIS, is extension added to database %s ?", url)
25
- raise psycopg2.errors.UndefinedFunction
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
- with self.conn:
60
- with self.conn.cursor() as curs:
61
- curs.execute(sql, params)
62
- result = curs.fetchall()
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
- with self.conn:
68
- with self.conn.cursor() as curs:
69
- result = curs.execute(sql, params)
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
- with self.conn:
75
- with self.conn.cursor() as curs:
76
- curs.executemany(sql, params)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bcdata
3
- Version: 0.10.1
3
+ Version: 0.10.2
4
4
  Summary: Python tools for quick access to DataBC geo-data available via WFS
5
5
  Home-page: https://github.com/smnorris/bcdata
6
6
  Author: Simon Norris
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