Beispiel #1
0
    def save(self):
        # existing user
        if self.id:
            db_conn.execute('''SELECT * FROM users WHERE id = ?''', self.id)
            raise NotImplementedException('''can't modify users yet''')

        db_conn.execute(
            '''INSERT INTO users (name, admin, pwhash) VALUES
                        (?, ?, ?)''', (self.name, self.admin, self.pwhash))

        g.db_modified = True
Beispiel #2
0
def setup_db():
    # running every db migration in order should get us an up-to-date DB
    db_conn.execute("BEGIN TRANSACTION")
    c = db_conn.execute('''SELECT name FROM sqlite_master
                        WHERE type="table" AND name="migrations"''')
    if not c.fetchone():
        # no migrations table present, let's start fresh
        print("No migrations table found, creating")
        create_migrations_table()

    max_migration = find_max_migration()
    print("Found migrations table, running from migration %d" % max_migration)

    migrations = find_migrations(max_migration)
    execute_migrations(migrations)
Beispiel #3
0
def find_max_migration():
    c = db_conn.execute('''SELECT * FROM migrations ORDER BY id DESC
                        LIMIT 1''')
    row = c.fetchone()
    if not row:
        return 0
    else:
        return row[0]
Beispiel #4
0
 def __getitem__(self, key):
     key = dumps(key, 0)
     rv = None
     for row in db_conn.execute(self._get_sql, (key,)):
         rv = loads(str(row[0]))
         break
     if rv is None:
         raise KeyError('Key not in this session')
     return rv
Beispiel #5
0
 def __len__(self):
     for row in db_conn.execute(self._len_sql):
         return row[0]
Beispiel #6
0
 def __iter__(self):
     for row in db_conn.execute(self._ite_sql):
         yield loads(str(row[0]))
Beispiel #7
0
 def __delitem__(self, key):
     key = dumps(key, 0)
     db_conn.execute(self._del_sql, (key,))
     self.modified = True
Beispiel #8
0
 def __setitem__(self, key, value):
     key = dumps(key, 0)
     value = buffer(dumps(value, 2))
     db_conn.execute(self._set_sql, (key, value))
     self.modified = True
Beispiel #9
0
def mark_migration_complete(migration_id):
    db_conn.execute(
        '''INSERT INTO migrations (id, run_date) VALUES
                    (?, datetime('now'))''', (migration_id, ))
Beispiel #10
0
def create_migrations_table():
    db_conn.execute('''CREATE TABLE migrations (id INTEGER PRIMARY KEY,
        run_date TEXT)''')