Added templetor support to page creator
[kisspi.git] / kisspidb.py
1 '''
2 # EXAMPLE TABLE
3
4 from hashlib import sha256 as sha
5 from sqlalchemy import *
6
7 Base = kisspi.db.base()
8
9 # sqlalchemy definition
10
11 class User(Base):
12     __tablename__ = 'users'
13
14     id = Column(Integer, primary_key=True)
15     name = Column(String(20), unique=True)
16     password = Column(String(60))
17
18     def set_password(self, password):
19         self.password = sha(password).hexdigest()
20
21     def __init__(self, name, password):
22         self.name = name
23         self.set_password(password)
24
25 kisspi.db.create(Base)
26
27 # MAKING QUERIES
28
29 session = kisspi.db.connect()
30 session.query(User).filter(User.name == 'danigm').first()
31 '''
32
33 from sqlalchemy import create_engine
34 from sqlalchemy.ext.declarative import declarative_base as base
35 from sqlalchemy.orm import sessionmaker
36
37 DATABASE = 'sqlite:///database.sqlite'
38
39 def connect():
40     database = DATABASE
41     db = create_engine(database, echo=False)
42     Session = sessionmaker(bind=db, autoflush=True)
43     session = Session()
44     return session
45
46 def create(Base):
47     database = DATABASE
48     db = create_engine(database, echo=False)
49     metadata = Base.metadata
50     metadata.create_all(db)
51