-
Notifications
You must be signed in to change notification settings - Fork 210
Database layer
Joram van den Boezem edited this page Jun 2, 2017
·
1 revision
db = DB.get_instance() # type: DB
db.query("DROP TABLE IF EXISTS users ")
db.query("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT NOT NULL)")
db.query("INSERT INTO users (name) VALUES (?)", ['test1'])
db.query("INSERT INTO users (name) VALUES (?)", ['test2'])
db.query("INSERT INTO users (name) VALUES (?)", ['test3'])
print(db.query("SELECT * FROM users"))
print(db.row("SELECT * FROM users"))
print(db.one("SELECT * FROM users"))
yields:
[{'id': 1, 'name': 'test1'}, {'id': 2, 'name': 'test2'}, {'id': 3, 'name': 'test3'}]
{'id': 1, 'name': 'test1'}
1
Currently, sqlite and mysql are supported. Adapter and configuration are in settings.py
.