aisdb.database.dbconn module

class aisdb.database.dbconn.ConnectionType(value)[source]

Bases: Enum

database connection types enum. used for static type hints

POSTGRES = <class 'aisdb.database.dbconn.PostgresDBConn'>
aisdb.database.dbconn.DBConn

alias of PostgresDBConn

class aisdb.database.dbconn.PostgresDBConn(libpq_connstring=None, **kwargs)[source]

Bases: _DBConn, Connection

This feature requires optional dependency psycopg for interfacing Postgres databases.

The following keyword arguments are accepted by Postgres: | https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

Alternatively, a connection string may be used. Information on connection strings and postgres URI format can be found here: | https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING

Example:

import os
from aisdb.database.dbconn import PostgresDBConn

# keyword arguments
dbconn = PostgresDBConn(
    hostaddr='127.0.0.1',
    user='postgres',
    port=5432,
    password=os.environ.get('POSTGRES_PASSWORD'),
    dbname='postgres',
)

# Alternatively, connect using a connection string:
dbconn = PostgresDBConn('Postgresql://localhost:5433')
aggregate_static_msgs(verbose: bool = True)[source]

collect an aggregate of static vessel reports for each unique MMSI identifier. The most frequently repeated values for each MMSI will be kept when multiple different reports appear for the same MMSI

this function should be called every time data is added to the database

Parameters:

verbose (bool) – logs messages to stdout

deduplicate_dynamic_msgs(verbose=True)[source]
drop_indexes(verbose=True)[source]
execute(sql, args=[])[source]

Execute a query and return a cursor to read its results.

rebuild_indexes(verbose=True)[source]