예제 #1
0
        ("journal_mode", "wal"),
        ("ignore_check_constraints", 0),
        ("synchronous", "normal"),
    ],
)


class Users(peewee.Model):
    id = peewee.IntegerField(primary_key=True,
                             constraints=[peewee.Check(constraint="id > 0")])

    first_name = peewee.CharField(max_length=255)
    last_name = peewee.CharField(max_length=255, default=None, null=True)
    username = peewee.CharField(max_length=32, default=None, null=True)
    timestamp = peewee.DateTimeField(default=datetime.datetime.utcnow,
                                     null=False)
    # prevent forwards to master
    is_blocked = peewee.BooleanField(
        default=False,
        null=False,
        constraints=[peewee.Check(constraint="is_blocked BETWEEN 0 AND 1")],
    )

    class Meta:
        database = DB


DB.create_tables(models=[Users], safe=True)
DB.close()
DB.connect()
예제 #2
0
    os.remove("reproduce.db")
if os.path.exists("peewee.db"):
    os.remove("peewee.db")

db = SqliteQueueDatabase(None)


class TestModel(Model):
    test = CharField(null=True)

    class Meta(object):
        database = db


db.init("reproduce.db")
TestModel.create_table()

was_started = db.start()
print("Database was started: %s" % was_started)
was_stopped = db.stop()
print("Database was stopped: %s" % was_stopped)
print("Database is stopped: %s" % db.is_stopped())
db.close()
is_closed = db.is_closed()
print("Database is closed: %s" % is_closed)
try:
    os.unlink("reproduce.db")
    print("Database file was deleted")
except Exception:
    print("Database file still locked")