sqlspec 0.8.0__py3-none-any.whl → 0.9.0__py3-none-any.whl

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.

Potentially problematic release.


This version of sqlspec might be problematic. Click here for more details.

Files changed (45) hide show
  1. sqlspec/_typing.py +39 -6
  2. sqlspec/adapters/adbc/__init__.py +2 -2
  3. sqlspec/adapters/adbc/config.py +34 -11
  4. sqlspec/adapters/adbc/driver.py +167 -108
  5. sqlspec/adapters/aiosqlite/__init__.py +2 -2
  6. sqlspec/adapters/aiosqlite/config.py +2 -2
  7. sqlspec/adapters/aiosqlite/driver.py +28 -39
  8. sqlspec/adapters/asyncmy/__init__.py +3 -3
  9. sqlspec/adapters/asyncmy/config.py +11 -12
  10. sqlspec/adapters/asyncmy/driver.py +25 -34
  11. sqlspec/adapters/asyncpg/__init__.py +5 -5
  12. sqlspec/adapters/asyncpg/config.py +17 -19
  13. sqlspec/adapters/asyncpg/driver.py +249 -93
  14. sqlspec/adapters/duckdb/__init__.py +2 -2
  15. sqlspec/adapters/duckdb/config.py +2 -2
  16. sqlspec/adapters/duckdb/driver.py +49 -49
  17. sqlspec/adapters/oracledb/__init__.py +8 -8
  18. sqlspec/adapters/oracledb/config/__init__.py +6 -6
  19. sqlspec/adapters/oracledb/config/_asyncio.py +9 -10
  20. sqlspec/adapters/oracledb/config/_sync.py +8 -9
  21. sqlspec/adapters/oracledb/driver.py +114 -41
  22. sqlspec/adapters/psqlpy/__init__.py +0 -0
  23. sqlspec/adapters/psqlpy/config.py +258 -0
  24. sqlspec/adapters/psqlpy/driver.py +335 -0
  25. sqlspec/adapters/psycopg/__init__.py +10 -5
  26. sqlspec/adapters/psycopg/config/__init__.py +6 -6
  27. sqlspec/adapters/psycopg/config/_async.py +12 -12
  28. sqlspec/adapters/psycopg/config/_sync.py +13 -13
  29. sqlspec/adapters/psycopg/driver.py +180 -218
  30. sqlspec/adapters/sqlite/__init__.py +2 -2
  31. sqlspec/adapters/sqlite/config.py +2 -2
  32. sqlspec/adapters/sqlite/driver.py +43 -41
  33. sqlspec/base.py +275 -153
  34. sqlspec/exceptions.py +30 -0
  35. sqlspec/extensions/litestar/config.py +6 -0
  36. sqlspec/extensions/litestar/handlers.py +25 -0
  37. sqlspec/extensions/litestar/plugin.py +6 -1
  38. sqlspec/statement.py +373 -0
  39. sqlspec/typing.py +10 -1
  40. {sqlspec-0.8.0.dist-info → sqlspec-0.9.0.dist-info}/METADATA +4 -1
  41. sqlspec-0.9.0.dist-info/RECORD +61 -0
  42. sqlspec-0.8.0.dist-info/RECORD +0 -57
  43. {sqlspec-0.8.0.dist-info → sqlspec-0.9.0.dist-info}/WHEEL +0 -0
  44. {sqlspec-0.8.0.dist-info → sqlspec-0.9.0.dist-info}/licenses/LICENSE +0 -0
  45. {sqlspec-0.8.0.dist-info → sqlspec-0.9.0.dist-info}/licenses/NOTICE +0 -0
@@ -16,18 +16,18 @@ if TYPE_CHECKING:
16
16
 
17
17
 
18
18
  __all__ = (
19
- "PsycopgAsync",
20
- "PsycopgAsyncPool",
19
+ "PsycopgAsyncConfig",
20
+ "PsycopgAsyncPoolConfig",
21
21
  )
22
22
 
23
23
 
24
24
  @dataclass
25
- class PsycopgAsyncPool(PsycopgGenericPoolConfig[AsyncConnection, AsyncConnectionPool]):
25
+ class PsycopgAsyncPoolConfig(PsycopgGenericPoolConfig[AsyncConnection, AsyncConnectionPool]):
26
26
  """Async Psycopg Pool Config"""
27
27
 
28
28
 
29
29
  @dataclass
30
- class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, PsycopgAsyncDriver]):
30
+ class PsycopgAsyncConfig(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, PsycopgAsyncDriver]):
31
31
  """Async Psycopg database Configuration.
32
32
 
33
33
  This class provides the base configuration for Psycopg database connections, extending
@@ -37,7 +37,7 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
37
37
  with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
38
38
  """
39
39
 
40
- pool_config: "Optional[PsycopgAsyncPool]" = None
40
+ pool_config: "Optional[PsycopgAsyncPoolConfig]" = None
41
41
  """Psycopg Pool configuration"""
42
42
  pool_instance: "Optional[AsyncConnectionPool]" = None
43
43
  """Optional pool to use"""
@@ -71,7 +71,7 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
71
71
  self.pool_config,
72
72
  exclude_empty=True,
73
73
  convert_nested=False,
74
- exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type"}),
74
+ exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type", "open"}),
75
75
  )
76
76
  msg = "You must provide a 'pool_config' for this adapter."
77
77
  raise ImproperConfigurationError(msg)
@@ -94,7 +94,7 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
94
94
  raise ImproperConfigurationError(msg)
95
95
 
96
96
  async def create_connection(self) -> "AsyncConnection":
97
- """Create and return a new psycopg async connection.
97
+ """Create and return a new psycopg async connection from the pool.
98
98
 
99
99
  Returns:
100
100
  An AsyncConnection instance.
@@ -103,9 +103,8 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
103
103
  ImproperConfigurationError: If the connection could not be created.
104
104
  """
105
105
  try:
106
- from psycopg import AsyncConnection
107
-
108
- return await AsyncConnection.connect(**self.connection_config_dict)
106
+ pool = await self.provide_pool()
107
+ return await pool.getconn()
109
108
  except Exception as e:
110
109
  msg = f"Could not configure the Psycopg connection. Error: {e!s}"
111
110
  raise ImproperConfigurationError(msg) from e
@@ -128,10 +127,11 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
128
127
  raise ImproperConfigurationError(msg)
129
128
 
130
129
  pool_config = self.pool_config_dict
131
- self.pool_instance = AsyncConnectionPool(**pool_config)
130
+ self.pool_instance = AsyncConnectionPool(open=False, **pool_config)
132
131
  if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
133
132
  msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
134
133
  raise ImproperConfigurationError(msg)
134
+ await self.pool_instance.open()
135
135
  return self.pool_instance
136
136
 
137
137
  def provide_pool(self, *args: "Any", **kwargs: "Any") -> "Awaitable[AsyncConnectionPool]":
@@ -150,7 +150,7 @@ class PsycopgAsync(AsyncDatabaseConfig[AsyncConnection, AsyncConnectionPool, Psy
150
150
  AsyncConnection: A database connection from the pool.
151
151
  """
152
152
  pool = await self.provide_pool(*args, **kwargs)
153
- async with pool.connection() as connection:
153
+ async with pool, pool.connection() as connection:
154
154
  yield connection
155
155
 
156
156
  @asynccontextmanager
@@ -16,18 +16,18 @@ if TYPE_CHECKING:
16
16
 
17
17
 
18
18
  __all__ = (
19
- "PsycopgSync",
20
- "PsycopgSyncPool",
19
+ "PsycopgSyncConfig",
20
+ "PsycopgSyncPoolConfig",
21
21
  )
22
22
 
23
23
 
24
24
  @dataclass
25
- class PsycopgSyncPool(PsycopgGenericPoolConfig[Connection, ConnectionPool]):
25
+ class PsycopgSyncPoolConfig(PsycopgGenericPoolConfig[Connection, ConnectionPool]):
26
26
  """Sync Psycopg Pool Config"""
27
27
 
28
28
 
29
29
  @dataclass
30
- class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriver]):
30
+ class PsycopgSyncConfig(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriver]):
31
31
  """Sync Psycopg database Configuration.
32
32
  This class provides the base configuration for Psycopg database connections, extending
33
33
  the generic database configuration with Psycopg-specific settings.([1](https://www.psycopg.org/psycopg3/docs/api/connections.html))
@@ -36,7 +36,7 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
36
36
  with both synchronous and asynchronous connections.([2](https://www.psycopg.org/psycopg3/docs/api/connections.html))
37
37
  """
38
38
 
39
- pool_config: "Optional[PsycopgSyncPool]" = None
39
+ pool_config: "Optional[PsycopgSyncPoolConfig]" = None
40
40
  """Psycopg Pool configuration"""
41
41
  pool_instance: "Optional[ConnectionPool]" = None
42
42
  """Optional pool to use"""
@@ -70,7 +70,7 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
70
70
  self.pool_config,
71
71
  exclude_empty=True,
72
72
  convert_nested=False,
73
- exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type"}),
73
+ exclude=pool_only_params.union({"pool_instance", "connection_type", "driver_type", "open"}),
74
74
  )
75
75
  msg = "You must provide a 'pool_config' for this adapter."
76
76
  raise ImproperConfigurationError(msg)
@@ -87,13 +87,13 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
87
87
  self.pool_config,
88
88
  exclude_empty=True,
89
89
  convert_nested=False,
90
- exclude={"pool_instance", "connection_type", "driver_type"},
90
+ exclude={"pool_instance", "connection_type", "driver_type", "open"},
91
91
  )
92
92
  msg = "'pool_config' methods can not be used when a 'pool_instance' is provided."
93
93
  raise ImproperConfigurationError(msg)
94
94
 
95
95
  def create_connection(self) -> "Connection":
96
- """Create and return a new psycopg connection.
96
+ """Create and return a new psycopg connection from the pool.
97
97
 
98
98
  Returns:
99
99
  A Connection instance.
@@ -102,9 +102,8 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
102
102
  ImproperConfigurationError: If the connection could not be created.
103
103
  """
104
104
  try:
105
- from psycopg import connect
106
-
107
- return connect(**self.connection_config_dict)
105
+ pool = self.provide_pool()
106
+ return pool.getconn()
108
107
  except Exception as e:
109
108
  msg = f"Could not configure the Psycopg connection. Error: {e!s}"
110
109
  raise ImproperConfigurationError(msg) from e
@@ -127,10 +126,11 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
127
126
  raise ImproperConfigurationError(msg)
128
127
 
129
128
  pool_config = self.pool_config_dict
130
- self.pool_instance = ConnectionPool(**pool_config)
129
+ self.pool_instance = ConnectionPool(open=False, **pool_config)
131
130
  if self.pool_instance is None: # pyright: ignore[reportUnnecessaryComparison]
132
131
  msg = "Could not configure the 'pool_instance'. Please check your configuration." # type: ignore[unreachable]
133
132
  raise ImproperConfigurationError(msg)
133
+ self.pool_instance.open()
134
134
  return self.pool_instance
135
135
 
136
136
  def provide_pool(self, *args: "Any", **kwargs: "Any") -> "ConnectionPool":
@@ -149,7 +149,7 @@ class PsycopgSync(SyncDatabaseConfig[Connection, ConnectionPool, PsycopgSyncDriv
149
149
  Connection: A database connection from the pool.
150
150
  """
151
151
  pool = self.provide_pool(*args, **kwargs)
152
- with pool.connection() as connection:
152
+ with pool, pool.connection() as connection:
153
153
  yield connection
154
154
 
155
155
  @contextmanager