aisdb.database.dbconn module

SQLite Database connection

Also see: https://docs.python.org/3/library/sqlite3.html#connection-objects

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

Bases: Enum

database connection types enum. used for static type hints

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

alias of SQLiteDBConn

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(months_str: list, 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:
  • months_str (list) – list of strings with format: YYYYmm

  • verbose (bool) – logs messages to stdout

cursor_factory: Type[Cursor[Row]]
deduplicate_dynamic_msgs(month: str, verbose=True)[source]
execute(sql, args=[])[source]

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

rebuild_indexes(month, verbose=True)[source]
row_factory: RowFactory[Row]
server_cursor_factory: Type[ServerCursor[Row]]
class aisdb.database.dbconn.SQLiteDBConn(dbpath)[source]

Bases: _DBConn, Connection

SQLite3 database connection object

dbpath

database filepath

Type:

str

db_daterange

temporal range of monthly database tables. keys are DB file names

Type:

dict

aggregate_static_msgs(months_str: list, 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:
  • dbconn (aisdb.database.dbconn.SQLiteDBConn) – database connection object

  • months_str (list) – list of strings with format: YYYYmm

  • verbose (bool) – logs messages to stdout