-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
51 lines (42 loc) · 1.77 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlalchemy
from sqlalchemy.orm import scoped_session, sessionmaker, mapper
from sqlalchemy import MetaData
from sqlalchemy import Column, MetaData, Table, types
from datetime import datetime
class Message(object):
pass
metadata = sqlalchemy.MetaData()
message = Table("message", metadata,
Column('id', types.BigInteger(20), primary_key=True),
Column('parent_id', types.BigInteger(20)),
Column('incident_id', types.Integer(11)),
Column('user_id', types.Integer(11)),
Column('reporter_id', types.BigInteger(20)),
Column('service_messageid', types.Unicode(100)),
Column('message_from', types.Unicode(100)),
Column('message_to', types.Unicode(100)),
Column('message', types.Unicode),
Column('message_detail', types.Unicode),
Column('message_type', types.SmallInteger(4)),
Column('message_date', types.DateTime),
Column('message_level',types.SmallInteger(4)),
Column('type', types.Integer(4)),
mysql_engine = 'InnoDB',
mysql_charset = 'utf8'
)
def startSession(conf):
config = {"sqlalchemy.url":
"mysql://"+conf["dbuser"]+":"+conf["dbpass"]+"@"+conf["dbhost"]+"/"+conf["db"]+"?charset=utf8",
"sqlalchemy.echo":"False"}
engine = sqlalchemy.engine_from_config(config)
dbSession = scoped_session(
sessionmaker(
autoflush = True,
autocommit = False,
bind = engine
)
)
mapper(Message, message)
return dbSession