mirror of
https://github.com/sigmasternchen/Diary
synced 2025-03-15 15:18:57 +00:00
Added database and User-model
This commit is contained in:
parent
a7b33e30d4
commit
bc1da82f7e
2 changed files with 31 additions and 0 deletions
17
database.py
Executable file
17
database.py
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env python2.7
|
||||||
|
|
||||||
|
from sqlalchemy import create_engine,event,exc
|
||||||
|
from sqlalchemy.orm import scoped_session,sessionmaker
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
|
engine=create_engine('sqlite:///sqlite.db',convert_unicode=True)
|
||||||
|
db_session=scoped_session(sessionmaker(autocommit=False,autoflush=True,bind=engine))
|
||||||
|
Base=declarative_base()
|
||||||
|
Base.query=db_session.query_property()
|
||||||
|
|
||||||
|
def init_db():
|
||||||
|
import models
|
||||||
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
|
if __name__=='__name__':
|
||||||
|
init_db()
|
14
models.py
Executable file
14
models.py
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/usr/bin/env python2.7
|
||||||
|
|
||||||
|
from sqlalchemy import Column,Integer,String
|
||||||
|
from database import Base
|
||||||
|
|
||||||
|
class User(Base):
|
||||||
|
__tablename__='users'
|
||||||
|
id=Column(Integer(),primary_key=True,unique=True)
|
||||||
|
username=Column(String(256),unique=True)
|
||||||
|
password=Column(String(128))
|
||||||
|
|
||||||
|
def __init__(self,username,password):
|
||||||
|
self.username=username
|
||||||
|
self.password=password
|
Loading…
Reference in a new issue