-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.py
More file actions
38 lines (22 loc) · 637 Bytes
/
Copy pathdb.py
File metadata and controls
38 lines (22 loc) · 637 Bytes
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
import sqlite3
import atexit
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
conn = sqlite3.connect('database.db')
engine = create_engine('sqlite:///database.db')
Session = sessionmaker(bind=engine)
session = Session()
def execute_raw(raw_sql):
return conn.executescript(raw_sql)
def select(table):
return sqlalchemy.select([table])
def query(table):
return session.query(table)
def insert(table):
return sqlalchemy.insert(table)
def update(table):
return sqlalchemy.update(table)
def close_database():
conn.close()
engine.dispose()
atexit.register(close_database)