initial commit
This commit is contained in:
49
venv/Lib/site-packages/adbc_driver_duckdb/__init__.py
Normal file
49
venv/Lib/site-packages/adbc_driver_duckdb/__init__.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Low-level ADBC bindings for the DuckDB driver."""
|
||||
|
||||
import enum
|
||||
import functools
|
||||
import importlib.util
|
||||
import typing
|
||||
|
||||
import adbc_driver_manager
|
||||
|
||||
|
||||
class StatementOptions(enum.Enum):
|
||||
"""Statement options specific to the DuckDB driver."""
|
||||
|
||||
#: The number of rows per batch. Defaults to 2048.
|
||||
BATCH_ROWS = "adbc.duckdb.query.batch_rows"
|
||||
|
||||
|
||||
def connect(path: typing.Optional[str] = None) -> adbc_driver_manager.AdbcDatabase:
|
||||
"""Create a low level ADBC connection to DuckDB."""
|
||||
if path is None:
|
||||
return adbc_driver_manager.AdbcDatabase(driver=driver_path(), entrypoint="duckdb_adbc_init")
|
||||
return adbc_driver_manager.AdbcDatabase(driver=driver_path(), entrypoint="duckdb_adbc_init", path=path)
|
||||
|
||||
|
||||
@functools.cache
|
||||
def driver_path() -> str:
|
||||
"""Get the path to the DuckDB ADBC driver."""
|
||||
duckdb_module_spec = importlib.util.find_spec("_duckdb")
|
||||
if duckdb_module_spec is None:
|
||||
msg = "Could not find duckdb shared library. Did you pip install duckdb?"
|
||||
raise ImportError(msg)
|
||||
return duckdb_module_spec.origin
|
||||
Binary file not shown.
Binary file not shown.
115
venv/Lib/site-packages/adbc_driver_duckdb/dbapi.py
Normal file
115
venv/Lib/site-packages/adbc_driver_duckdb/dbapi.py
Normal file
@@ -0,0 +1,115 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""DBAPI 2.0-compatible facade for the ADBC DuckDB driver."""
|
||||
|
||||
import typing
|
||||
|
||||
import adbc_driver_manager
|
||||
import adbc_driver_manager.dbapi
|
||||
|
||||
import adbc_driver_duckdb
|
||||
|
||||
__all__ = [
|
||||
"BINARY",
|
||||
"DATETIME",
|
||||
"NUMBER",
|
||||
"ROWID",
|
||||
"STRING",
|
||||
"Connection",
|
||||
"Cursor",
|
||||
"DataError",
|
||||
"DatabaseError",
|
||||
"Date",
|
||||
"DateFromTicks",
|
||||
"Error",
|
||||
"IntegrityError",
|
||||
"InterfaceError",
|
||||
"InternalError",
|
||||
"NotSupportedError",
|
||||
"OperationalError",
|
||||
"ProgrammingError",
|
||||
"Time",
|
||||
"TimeFromTicks",
|
||||
"Timestamp",
|
||||
"TimestampFromTicks",
|
||||
"Warning",
|
||||
"apilevel",
|
||||
"connect",
|
||||
"paramstyle",
|
||||
"threadsafety",
|
||||
]
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Globals
|
||||
|
||||
apilevel = adbc_driver_manager.dbapi.apilevel
|
||||
threadsafety = adbc_driver_manager.dbapi.threadsafety
|
||||
paramstyle = "qmark"
|
||||
|
||||
Warning = adbc_driver_manager.dbapi.Warning
|
||||
Error = adbc_driver_manager.dbapi.Error
|
||||
InterfaceError = adbc_driver_manager.dbapi.InterfaceError
|
||||
DatabaseError = adbc_driver_manager.dbapi.DatabaseError
|
||||
DataError = adbc_driver_manager.dbapi.DataError
|
||||
OperationalError = adbc_driver_manager.dbapi.OperationalError
|
||||
IntegrityError = adbc_driver_manager.dbapi.IntegrityError
|
||||
InternalError = adbc_driver_manager.dbapi.InternalError
|
||||
ProgrammingError = adbc_driver_manager.dbapi.ProgrammingError
|
||||
NotSupportedError = adbc_driver_manager.dbapi.NotSupportedError
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Types
|
||||
|
||||
Date = adbc_driver_manager.dbapi.Date
|
||||
Time = adbc_driver_manager.dbapi.Time
|
||||
Timestamp = adbc_driver_manager.dbapi.Timestamp
|
||||
DateFromTicks = adbc_driver_manager.dbapi.DateFromTicks
|
||||
TimeFromTicks = adbc_driver_manager.dbapi.TimeFromTicks
|
||||
TimestampFromTicks = adbc_driver_manager.dbapi.TimestampFromTicks
|
||||
STRING = adbc_driver_manager.dbapi.STRING
|
||||
BINARY = adbc_driver_manager.dbapi.BINARY
|
||||
NUMBER = adbc_driver_manager.dbapi.NUMBER
|
||||
DATETIME = adbc_driver_manager.dbapi.DATETIME
|
||||
ROWID = adbc_driver_manager.dbapi.ROWID
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Functions
|
||||
|
||||
|
||||
def connect(path: typing.Optional[str] = None, **kwargs) -> "Connection":
|
||||
"""Connect to DuckDB via ADBC."""
|
||||
db = None
|
||||
conn = None
|
||||
|
||||
try:
|
||||
db = adbc_driver_duckdb.connect(path)
|
||||
conn = adbc_driver_manager.AdbcConnection(db)
|
||||
return adbc_driver_manager.dbapi.Connection(db, conn, **kwargs)
|
||||
except Exception:
|
||||
if conn:
|
||||
conn.close()
|
||||
if db:
|
||||
db.close()
|
||||
raise
|
||||
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Classes
|
||||
|
||||
Connection = adbc_driver_manager.dbapi.Connection
|
||||
Cursor = adbc_driver_manager.dbapi.Cursor
|
||||
Reference in New Issue
Block a user