atoti_jdbc.JdbcLoad#
- final class atoti_jdbc.JdbcLoad#
The description of a JDBC query.
Example
>>> from atoti_jdbc import JdbcLoad >>> url = f"h2:{database_path};USER=root;PASSWORD=pass" >>> jdbc_load = JdbcLoad("SELECT * FROM MYTABLE", url=url)
Inferring data types:
>>> data_types = session.tables.infer_data_types(jdbc_load) >>> data_types {'ID': 'int', 'CITY': 'String', 'MY_VALUE': 'long'}
Creating table from inferred data types:
>>> table = session.create_table( ... "Cities", ... data_types=data_types, ... keys={"ID"}, ... )
Loading query results into the table:
>>> table.load(jdbc_load) >>> table.head().sort_index() CITY MY_VALUE ID 1 Paris 100 2 London 80 3 New York 90 4 Berlin 70 5 Jakarta 75 >>> table.drop()
Using a parametrized query:
>>> table.load( ... JdbcLoad( ... "SELECT * FROM MYTABLE WHERE City IN (?, ?)", ... parameters=["Paris", "New York"], ... url=url, ... ) ... ) >>> table.head().sort_index() CITY MY_VALUE ID 1 Paris 100 3 New York 90
See also
The other
DataLoad
implementations.- driver: Annotated[str | None, AfterValidator(_validate_driver)] = None#
The Java class name of the
driver
to use.This defines Hibernate’s DRIVER option.
Inferred from
url
ifNone
.
- parameters: Sequence[ConstantValue] = ()#
The query parameters, sometimes also called bind variables.
- url: Annotated[str, AfterValidator(normalize_jdbc_url)]#
The JDBC connection string of the database.
The
"jdbc"
scheme is optional but the database specific scheme (such as"h2"
or"mysql"
) is mandatory. For instance:"h2:/home/user/database/file/path;USER=username;PASSWORD=passwd"
"mysql://localhost:7777/example?user=username&password=passwd"
"postgresql://postgresql.db.server:5430/example?user=username&password=passwd"
More examples can be found here.
This defines Hibernate’s URL option.