apsw, an advanced sqlite driver
The apsw_ext
module contains a database class suitable for use withthe apsw sqlite driver.
APSW Project page: https://github.com/rogerbinns/apsw
APSW is a really neat library that provides a thin wrapper on top of SQLite’sC interface, making it possible to use all of SQLite’s advanced features.
Here are just a few reasons to use APSW, taken from the documentation:
- APSW gives all functionality of SQLite, including virtual tables, virtualfile system, blob i/o, backups and file control.
- Connections can be shared across threads without any additional locking.
- Transactions are managed explicitly by your code.
- APSW can handle nested transactions.
- Unicode is handled correctly.
- APSW is faster.
For more information on the differences between apsw and pysqlite,check the apsw docs.
How to use the APSWDatabase
- from apsw_ext import *
- db = APSWDatabase(':memory:')
- class BaseModel(Model):
- class Meta:
- database = db
- class SomeModel(BaseModel):
- col1 = CharField()
- col2 = DateTimeField()
apsw_ext API notes
APSWDatabase
extends the SqliteExtDatabase
and inheritsits advanced features.
Parameters:
- database (string) – filename of sqlite database
- connect_kwargs – keyword arguments passed to apsw when opening a connection
registermodule
(_mod_name, mod_inst)- Provides a way of globally registering a module. For more information,see the documentation on virtual tables.
Parameters:
- **mod_name** (_string_) – name to use for module
- **mod_inst** (_object_) – an object implementing the [Virtual Table](http://rogerbinns.github.io/apsw/vtable.html#vttable-class) interface
Parameters:mod_name (string) – name to use for module
Note
Be sure to use the Field
subclasses defined in the apsw_ext
module, as they will properly handle adapting the data types for storage.
For example, instead of using peewee.DateTimeField
, be sure you are importingand using playhouse.apsw_ext.DateTimeField
.