The pq
module exposes Peliqan’s low-code data-centric and data pipeline functions. The pq
module is automatically available in Peliqan when you write Python code in Data apps and can be used in your local IDE by doing pip install peliqan
and using import peliqan as pq
in your code.
dbconn = pq.dbconnect('dw_2')
# Use this connection to read data
rows = dbconn.fetch('db_name', 'schema_name', 'table_name')
rows = dbconn.fetch('db_name', 'schema_name', 'table_name')
# Read data using custom query
rows = dbconn.fetch('db_name', query='SELECT * FROM schema_name.table_name')
# Get result as a data frame
df = dbconn.fetch('db_name', 'schema_name', 'table_name', df=True)
# Options:
# df = True: set to True to return a Dataframe instead of a list of objects
# fillna_with = '': replace Na (not a number) with a given value, e.g. in empty string
# fillnat_with= '': replace NaT (not a date)
# enable_python_types = True: use Python types in response
# enable_datetime_as_string = True: return datetime columns as string
# tz='UTC': timezone for datetimes
dbconn.insert('db_name', 'schema_name', 'table_name', record_dict)
dbconn.update('db_name', 'schema_name', 'table_name', 'row_pk_value', record_dict)
dbconn.upsert('db_name', 'schema_name', 'table_name', 'row_pk_value', record_dict)
dbconn.write('schema_name', 'table_name', [{'id': 1, 'name': 'John'}], pk='id')
# Write with a schema provided
object_schema = {
'properties': {
'id': {'type': 'integer'},
'name': {'type': 'string'}
}
}
dbconn.write('schema_name', 'table_name', [{'id': 1, 'name': 'John'}], object_schema, pk='id')
dbconn.execute('db_name', query='TRUNCATE TABLE schema_name.table_name')
trinoconn = pq.trinoconnect()