From df82748518afdabf323696ad7dfce0ff6265e0ca Mon Sep 17 00:00:00 2001 From: Awoodwhale Date: Mon, 20 Mar 2023 20:09:32 +0800 Subject: [PATCH] feat: create classes necessary for orm operations --- app/model.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 app/model.py diff --git a/app/model.py b/app/model.py new file mode 100644 index 0000000..a913e65 --- /dev/null +++ b/app/model.py @@ -0,0 +1,30 @@ +from pony.orm import * + +db = Database() +db.bind("sqlite", "./static/wordfreqapp.db", create_db=True) # bind sqlit file + + +class User(db.Entity): + _table_ = "user" # table name + name = PrimaryKey(str) + password = Optional(str) + start_date = Optional(str) + expiry_date = Optional(str) + + +class Article(db.Entity): + _table_ = "article" # table name + article_id = PrimaryKey(int, auto=True) + text = Optional(str) + source = Optional(str) + date = Optional(str) + level = Optional(str) + question = Optional(str) + + +db.generate_mapping(create_tables=True) # must mapping after class declaration + + +if __name__ == "__main__": + with db_session: + print(Article[2].text) # test get article which id=2 text content