Async External Database
This module provides functionality for working with external databases.
- class AsyncDatabaseTable(api, database, data=None)[source]
Bases:
Base- Parameters:
api (AsyncGeoboxClient)
database (AsyncDatabase)
data (Dict | None)
- BASE_ENDPOINT = 'dbImport/'
- __init__(api, database, data=None)[source]
Constructs all the necessary attributes for the DatabaseTable object.
- Parameters:
api (GeoboxClient) – The GeoboxClient instance.
database (Database) – the Database instance.
data (Dict, optional) – The data of the table.
- __repr__()[source]
Return a string representation of the DatabaseTable object.
- Returns:
A string representation of the DatabaseTable object.
- Return type:
str
- async import_spatial(table_name=None, out_layer_name=None, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
[async] Import a spatial table/layer from an external database and publish it as a vector layer.
- Parameters:
table_name (str, optional) – Source table or layer name in the external database
out_layer_name (str, optional) – Name for the new vector layer to create
input_srid (int, optional) – Source coordinate reference system EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox.aio import AsyncGeoboxClient >>> from geobox.aio.db_connection import AsyncDatabase, DBCredentials, DBType >>> async with AsyncGeoboxClient() as client: >>> creds = DBCredentials(...)
>>> tables = await AsyncDatabase.get_database_tables(client, creds) or >>> tables = await client.get_database_tables(creds)
>>> await tables[0].import_spatial()
- async import_non_spatial(table_name=None, out_table_name=None, report_errors=False, user_id=False)[source]
[async] Import a non-spatial table from an external database and publish it as a Geobox Table.
- Parameters:
table_name (str, optional) – Source table name in the external database
out_table_name (str, optional) – Name for the new table to create
report_errors (bool, optional) – Include per-row import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox.aio import AsyncGeoboxClient >>> from geobox.aio.db_connection import AsyncDatabase, DBCredentials, DBType >>> async with AsyncGeoboxClient() as client: >>> creds = DBCredentials(...)
>>> tables = await AsyncDatabase.get_database_tables(client, creds) or >>> tables = await client.get_database_tables(creds)
>>> await tables[0].import_non_spatial()
- async import_spatial_into_layer(layer_uuid, table_name=None, is_view=False, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
[async] Import a spatial table/layer from an external database and append its features into an existing vector layer identified by layer_uuid.
- Parameters:
layer_uuid (str) – UUID of the existing vector layer to import into
table_name (str, optional) – Source table or layer name in the external database
is_view (bool, optional) – Whether the target layer is a vector layer view. default: False
input_srid (int, optional) – Source CRS EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox.aio import AsyncGeoboxClient >>> from geobox.aio.db_connection import AsyncDatabase, DBCredentials, DBType >>> async with AsyncGeoboxClient() as client: >>> creds = DBCredentials(...)
>>> layer = await client.get_vectors()[0]
>>> tables = await AsyncDatabase.get_database_tables(client, creds) or >>> tables = await client.get_database_tables(creds)
>>> await tables[0].import_spatial_into_layer(layer_uuid=layer.uuid)
- async import_table(table_name=None, out_name=None, input_srid=None, input_geom_type=None, report_errors=False, user_id=None)[source]
[async] Import a spatial table/layer from an external database and append its features into an existing vector layer identified by layer_uuid.
This method acts as a dispatcher that automatically routes the import request to the appropriate method (import_spatial for tables with geometry columns or import_non_spatial for tables without geometry).
- Parameters:
table_name (str, optional) – Source table or layer name in the external database.
out_name (str, optional) – Name for the output resource (vector layer or table) in Geobox.
input_srid (int, optional) – Source CRS EPSG code
input_geom_type (str, optional) – Force a specific geometry type
report_errors (bool, optional) – Include per-feature import errors in the result. default: False
user_id (int, optional) – specific user. privileges required.
- Returns:
the import task object
- Return type:
Example
>>> from geobox.aio import AsyncGeoboxClient >>> from geobox.aio.db_connection import AsyncDatabase, DBCredentials, DBType >>> async with AsyncGeoboxClient() as client: >>> creds = DBCredentials(...)
>>> layer = await client.get_vectors()[0]
>>> tables = await AsyncDatabase.get_database_tables(client, creds) or >>> tables = await client.get_database_tables(creds)
>>> await tables[0].import()
See also
import_spatial(): For explicitly importing spatial tables
import_non_spatial(): For explicitly importing non-spatial tables
import_spatial_into_layer(): For importing into an existing layer
- class AsyncDatabase(api, creds)[source]
Bases:
Base- Parameters:
api (AsyncGeoboxClient)
creds (DBCredentials)
- BASE_ENDPOINT = 'dbImport/'
- __init__(api, creds)[source]
Constructs all the necessary attributes for the Database object.
- Parameters:
api (AsyncGeoboxClient) – The AsyncGeoboxClient instance.
creds (DBCredentials) – the database connection credentials
- __repr__()[source]
Return a string representation of the AsyncDatabase object.
- Returns:
A string representation of the AsyncDatabase object.
- Return type:
str
- async classmethod get_database_tables(api, creds)[source]
[async] Get the list of tha database tables
- Parameters:
api (AsyncGeoboxClient) – The AsyncGeoboxClient instance.
creds (DBCredentials) – the database connection credentials
- Returns:
list of the database tables
- Return type:
List[AsyncDatabaseTable]
Example
>>> from geobox.aio import AsyncGeoboxClient >>> from geobox.aio.db_connection import AsyncDatabase, DBCredentials, DBType >>> async with AsyncGeoboxClient() as client: >>> creds = DBCredentials(...)
>>> tables = await AsyncDatabase.get_database_tables(client, creds) or >>> tables = await client.get_database_tables(creds)