Simple control 'psycopg2'(PostgreSQL).
Project description
threadingpg
Control PostgreSQL using thread(s).
Initialize Connector
import threadingpg
connector = threadingpg.Connector(dbname='database_name', user='user_name', password='password', port=5432)
# ...
connector.close()
Drop, Create Table
mytable = MyTable()
connector.drop_table(mytable)
connector.create_table(mytable)
Create Table and Row Class
Table Class
import threadingpg
from threadingpg import datatype
class MyTable(threadingpg.data.Table):
table_name="mytable"
index = threadingpg.data.Column(data_type=datatype.serial)
name = threadingpg.data.Column(data_type=datatype.varchar())
# or
class MyTable(threadingpg.data.Table):
def __init__(self) -> None:
self.index = threadingpg.data.Column(data_type=datatype.serial)
self.name = threadingpg.data.Column(data_type=datatype.varchar())
super().__init__("mytable") # important position
Row Class
equal name of columns.
class MyRow(threadingpg.data.Row):
def __init__(self,
name:str=None) -> None:
self.name = name
Insert Row
mytable = MyTable()
myrow = MyRow("my_row")
connector.insert_row(mytable, myrow)
# or
connector.insert_dict(mytable, {"name":"my_row"})
Select Row
mytable = MyTable()
column_name_list, rows = connector.select(mytable)
for row in rows:
myrow = MyRow()
myrow.set_data(column_name_list, row)
print(f"output: {myrow.name}") # output: my_row
Select Where Conditions
mytable = MyTable()
condition_equal_1 = threadingpg.condition.Equal(mytable.index, 1)
condition_equal_2 = threadingpg.condition.Equal(mytable.index, 2)
condition_equal_3 = threadingpg.condition.Equal(mytable.index, 3)
conditions = threadingpg.condition.Or(condition_equal_1, condition_equal_2, condition_equal_3)
column_name_list, rows = connector.select(mytable, where=conditions)
Insert Row
mytable = MyTable()
myrow = MyRow("update_my_row")
condition_equal_0 = threadingpg.condition.Equal(mytable.index, 0)
connector.update_row(mytable, myrow, condition_equal_0)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
threadingpg-0.0.1.tar.gz
(12.7 kB
view hashes)
Built Distribution
Close
Hashes for threadingpg-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c727cea30b194246420ee880a293583e297ed121f1e894e9bde58a49c669c5c |
|
MD5 | df73d25299bd9cb25745fe3e3bfc3d42 |
|
BLAKE2b-256 | a03f3587066effc6eacbcc5af72cdc66a22223ab15f94467f04a2c3bcfa1d093 |