InitialCommit
commit
675558ebaa
@ -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])
|
@ -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()
|
Loading…
Reference in New Issue