:class:`~.DirectDBConnection` ================================================================================================================================================== .. py:class:: astropathdb.db_io.dbconnect.DirectDBConnection :single-line-parameter-list: Connect directly to an AstroPath SQL Server database to write tables. Writing requires database write permissions. Fill in ``creds`` with the 'username', 'password', 'IP', and 'port' of the SQL Server before connecting. .. admonition:: Examples Write a table to the 'test' database: .. code-block:: python from astropathdb.db_io import DirectDBConnection db = DirectDBConnection() db.creds = { "username": "", "password": "", "IP": "", "port": 1433, } db.open_connection(database="test") db.write_to_database(df, table_name="my_table") :class:`~.astropathdb.db_io.dbconnect.DirectDBConnection` *Attributes* -------------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.dbconnect.DirectDBConnection.dbengine astropathdb.db_io.dbconnect.DirectDBConnection.dbmeta astropathdb.db_io.dbconnect.DirectDBConnection.creds :class:`~.astropathdb.db_io.dbconnect.DirectDBConnection` *Methods* -------------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.dbconnect.DirectDBConnection.open_connection astropathdb.db_io.dbconnect.DirectDBConnection.write_to_database :class:`~.astropathdb.db_io.dbconnect.DirectDBConnection` *References* -------------------------------------------------------------------------------------------------------------------------------------------------- .. py:currentmodule:: astropathdb.db_io.dbconnect.DirectDBConnection *Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: dbengine :value: None .. py:attribute:: dbmeta :value: None .. py:attribute:: creds *Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: open_connection(database = 'test') :single-line-parameter-list: Connect to a database with ``creds``. Sets ``dbengine`` to the SQLAlchemy engine and ``dbmeta`` to the database's reflected table metadata. :param database: The database to connect to. .. py:method:: write_to_database(data, table_name, if_exists = 'append', *, index = False) :single-line-parameter-list: Write a dataframe to a database table. Connects to the 'test' database if no connection is open. Geometries in a :class:`~geopandas.GeoDataFrame` are written as well-known text. :param data: The data to write. :param table_name: The table to write to. :param if_exists: What to do if the table exists: 'fail', 'replace', or 'append'. :param index: Write the dataframe index as a column.