commit 675558ebaa4399c759f05ac63da63d4a35666c95 Author: Hofei90 <29521028+hofei90@users.noreply.github.com> Date: Sun May 3 23:00:21 2020 +0200 InitialCommit diff --git a/db_model.py b/db_model.py new file mode 100644 index 0000000..2ab8e98 --- /dev/null +++ b/db_model.py @@ -0,0 +1,22 @@ +import peewee + + +database = peewee.Proxy() + + +class BaseModel(peewee.Model): + class Meta: + database = database + + +class TestPeewee(BaseModel): + ts = peewee.DateTimeField() + typ = peewee.TextField() + value = peewee.FloatField() + + class Meta: + primary_key = peewee.CompositeKey('ts', 'typ') + + +def create_tables(): + database.create_tables([TestPeewee]) diff --git a/peewee_timescale_test.py b/peewee_timescale_test.py new file mode 100644 index 0000000..4a6d26b --- /dev/null +++ b/peewee_timescale_test.py @@ -0,0 +1,31 @@ +from peewee import PostgresqlDatabase +from sshtunnel import SSHTunnelForwarder +import toml +import os +import db_model as db + + +def config_laden(): + configfile = os.path.join(SKRIPTPFAD, "config.toml") + with open(configfile) as file: + return toml.loads(file.read()) + + +SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__)) +CONFIG = config_laden() + + +def main(): + with SSHTunnelForwarder( + (CONFIG["ssh"]["ip_server"], CONFIG["ssh"]["ssh_port"]), ssh_username=CONFIG["ssh"]["user"], + ssh_password=CONFIG["ssh"]["pw"], remote_bind_address=('127.0.0.1', CONFIG["pg"]["pgport"])) as server: + + db.database.initialize(PostgresqlDatabase(CONFIG["pg"]["pgdb"], + user=CONFIG["pg"]["pguser"], password=CONFIG["pg"]["pgpw"], + host="127.0.0.1", + port=server.local_bind_port)) + db.create_tables() + + +if __name__ == "__main__": + main()