mirror of
https://github.com/coleifer/peewee.git
synced 2026-05-06 07:56:41 -04:00
Get rid of SqliteExt* - it basically did nothing.
This commit is contained in:
@@ -3585,8 +3585,9 @@ class SqliteDatabase(Database):
|
||||
server_version = __sqlite_version__
|
||||
truncate_table = False
|
||||
|
||||
def __init__(self, database, regexp_function=False, *args, **kwargs):
|
||||
self._pragmas = kwargs.pop('pragmas', ())
|
||||
def __init__(self, database, pragmas=None, regexp_function=False,
|
||||
rank_functions=False, *args, **kwargs):
|
||||
self._pragmas = pragmas or ()
|
||||
super(SqliteDatabase, self).__init__(database, *args, **kwargs)
|
||||
self._aggregates = {}
|
||||
self._collations = {}
|
||||
@@ -3599,6 +3600,9 @@ class SqliteDatabase(Database):
|
||||
self.register_function(_sqlite_date_trunc, 'date_trunc', 2)
|
||||
if regexp_function:
|
||||
self.register_function(_sqlite_regexp, 'regexp', 2)
|
||||
if rank_functions:
|
||||
from playhouse.sqlite_udf import register_udf_groups, RANK
|
||||
register_udf_groups(self, RANK)
|
||||
|
||||
def init(self, database, pragmas=None, timeout=5, returning_clause=None,
|
||||
**kwargs):
|
||||
|
||||
@@ -27,10 +27,8 @@ from peewee import Insert
|
||||
from peewee import TimeField as _TimeField
|
||||
from peewee import logger
|
||||
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
|
||||
|
||||
class APSWDatabase(SqliteExtDatabase):
|
||||
class APSWDatabase(SqliteDatabase):
|
||||
server_version = tuple(int(i) for i in apsw.sqlitelibversion().split('.'))
|
||||
|
||||
def __init__(self, database, **kwargs):
|
||||
|
||||
@@ -12,10 +12,8 @@ from playhouse.pool import PooledPostgresqlDatabase
|
||||
from playhouse.pool import PooledPostgresqlExtDatabase
|
||||
from playhouse.pool import PooledPsycopg3Database
|
||||
from playhouse.pool import PooledSqliteDatabase
|
||||
from playhouse.pool import PooledSqliteExtDatabase
|
||||
from playhouse.postgres_ext import PostgresqlExtDatabase
|
||||
from playhouse.postgres_ext import Psycopg3Database
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
try:
|
||||
from playhouse.cysqlite_ext import CySqliteDatabase
|
||||
except ImportError:
|
||||
@@ -40,9 +38,7 @@ schemes = {
|
||||
'psycopg3': Psycopg3Database,
|
||||
'psycopg3+pool': PooledPsycopg3Database,
|
||||
'sqlite': SqliteDatabase,
|
||||
'sqliteext': SqliteExtDatabase,
|
||||
'sqlite+pool': PooledSqliteDatabase,
|
||||
'sqliteext+pool': PooledSqliteExtDatabase,
|
||||
}
|
||||
|
||||
def register_database(db_class, *names):
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ from playhouse.fields import PickleField
|
||||
try:
|
||||
from playhouse.cysqlite_ext import CySqliteDatabase as _SqliteDatabase
|
||||
except ImportError:
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase as _SqliteDatabase
|
||||
_SqliteDatabase = SqliteDatabase
|
||||
|
||||
|
||||
Sentinel = type('Sentinel', (object,), {})
|
||||
|
||||
@@ -305,14 +305,6 @@ class _PooledSqliteDatabase(PooledDatabase):
|
||||
class PooledSqliteDatabase(_PooledSqliteDatabase, SqliteDatabase):
|
||||
pass
|
||||
|
||||
try:
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
|
||||
class PooledSqliteExtDatabase(_PooledSqliteDatabase, SqliteExtDatabase):
|
||||
pass
|
||||
except ImportError:
|
||||
PooledSqliteExtDatabase = None
|
||||
|
||||
try:
|
||||
from playhouse.cysqlite_ext import CySqliteDatabase
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ import decimal
|
||||
import sys
|
||||
|
||||
from peewee import *
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
if sys.version_info[0] != 3:
|
||||
from pysqlcipher import dbapi2 as sqlcipher
|
||||
else:
|
||||
@@ -100,7 +99,3 @@ class _SqlCipherDatabase(object):
|
||||
|
||||
class SqlCipherDatabase(_SqlCipherDatabase, SqliteDatabase):
|
||||
pass
|
||||
|
||||
|
||||
class SqlCipherExtDatabase(_SqlCipherDatabase, SqliteExtDatabase):
|
||||
pass
|
||||
|
||||
@@ -843,35 +843,6 @@ class FTS5Model(BaseFTSModel):
|
||||
return getattr(cls, attr)
|
||||
|
||||
|
||||
class SqliteExtDatabase(SqliteDatabase):
|
||||
def __init__(self, database, rank_functions=True, json_contains=False,
|
||||
*args, **kwargs):
|
||||
super(SqliteExtDatabase, self).__init__(database, *args, **kwargs)
|
||||
self._row_factory = None
|
||||
|
||||
if rank_functions:
|
||||
register_udf_groups(self, RANK)
|
||||
if json_contains:
|
||||
register_udf_groups(self, JSON)
|
||||
|
||||
def _add_conn_hooks(self, conn):
|
||||
super(SqliteExtDatabase, self)._add_conn_hooks(conn)
|
||||
if self._row_factory:
|
||||
conn.row_factory = self._row_factory
|
||||
|
||||
def row_factory(self, fn):
|
||||
self._row_factory = fn
|
||||
|
||||
|
||||
class CSqliteExtDatabase(SqliteExtDatabase):
|
||||
# XXX: here today, gone tomorrow.
|
||||
def __init__(self, *args, **kwargs):
|
||||
warnings.warn('CSqliteExtDatabase is deprecated. For equivalent '
|
||||
'functionality use cysqlite_ext.CySqliteDatabase.',
|
||||
DeprecationWarning)
|
||||
super(CSqliteExtDatabase, self).__init__(*args, **kwargs)
|
||||
|
||||
|
||||
OP.MATCH = 'MATCH'
|
||||
|
||||
def match(lhs, rhs):
|
||||
|
||||
@@ -18,7 +18,7 @@ try:
|
||||
except ImportError:
|
||||
GThread = GQueue = GEvent = None
|
||||
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
from peewee import SqliteDatabase
|
||||
|
||||
|
||||
logger = logging.getLogger('peewee.sqliteq')
|
||||
@@ -188,7 +188,7 @@ class Writer(object):
|
||||
return obj.set_result(cursor, exc)
|
||||
|
||||
|
||||
class SqliteQueueDatabase(SqliteExtDatabase):
|
||||
class SqliteQueueDatabase(SqliteDatabase):
|
||||
WAL_MODE_ERROR_MESSAGE = ('SQLite must be configured to use the WAL '
|
||||
'journal mode when using this feature. WAL mode '
|
||||
'allows one or more readers to continue reading '
|
||||
|
||||
@@ -16,12 +16,10 @@ PRAGMAS = {
|
||||
'cipher_log_level': 'none',
|
||||
}
|
||||
db = SqlCipherDatabase('peewee_test.dbc', passphrase=PASSPHRASE,
|
||||
pragmas=PRAGMAS)
|
||||
ext_db = SqlCipherExtDatabase('peewee_test.dbx', passphrase=PASSPHRASE,
|
||||
pragmas=PRAGMAS)
|
||||
pragmas=PRAGMAS, rank_functions=True)
|
||||
|
||||
|
||||
@ext_db.func('shazam')
|
||||
@db.func('shazam')
|
||||
def shazam(s):
|
||||
return sha1((s or '').encode('utf-8')).hexdigest()[:5]
|
||||
|
||||
@@ -122,12 +120,12 @@ class TestSqlCipherConfiguration(CleanUpModelTestCase):
|
||||
|
||||
|
||||
class SqlCipherExtTestCase(CleanUpModelTestCase):
|
||||
database = ext_db
|
||||
database = db
|
||||
requires = [Note]
|
||||
|
||||
def setUp(self):
|
||||
super(SqlCipherExtTestCase, self).setUp()
|
||||
FTSNote._meta.database = ext_db
|
||||
FTSNote._meta.database = db
|
||||
FTSNote.drop_table(True)
|
||||
FTSNote.create_table(tokenize='porter', content=Note.content)
|
||||
|
||||
@@ -154,7 +152,7 @@ class SqlCipherExtTestCase(CleanUpModelTestCase):
|
||||
'relational databases are the best',
|
||||
'sqlite is the best relational database'])
|
||||
|
||||
alt_conn = SqliteDatabase(ext_db.database)
|
||||
alt_conn = SqliteDatabase(db.database)
|
||||
self.assertRaises(
|
||||
DatabaseError,
|
||||
alt_conn.execute_sql,
|
||||
|
||||
+2
-78
@@ -27,7 +27,7 @@ from .sqlite_helpers import json_text_installed
|
||||
from .sqlite_helpers import jsonb_installed
|
||||
|
||||
|
||||
database = SqliteExtDatabase(':memory:', timeout=100)
|
||||
database = SqliteDatabase(':memory:', rank_functions=True, timeout=100)
|
||||
|
||||
|
||||
try:
|
||||
@@ -1513,82 +1513,6 @@ class TestRowIDField(ModelTestCase):
|
||||
self.assertEqual(5, RowIDModel.select(RowIDModel.rowid).first().rowid)
|
||||
|
||||
|
||||
@skip_unless(json_installed(), 'requires json1 sqlite extension')
|
||||
class TestJsonContains(ModelTestCase):
|
||||
database = SqliteExtDatabase(':memory:', json_contains=True)
|
||||
requires = [KeyData]
|
||||
test_data = (
|
||||
('a', {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'}),
|
||||
('b', {'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}),
|
||||
('c', {'k3': 'v3', 'x1': {'y1': 'z1', 'y2': 'z2'}}),
|
||||
('d', {'k4': 'v4', 'x1': {'y2': 'z2', 'y3': [0, 1, 2]}}),
|
||||
('e', ['foo', 'bar', [0, 1, 2]]),
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(TestJsonContains, self).setUp()
|
||||
with self.database.atomic():
|
||||
for key, data in self.test_data:
|
||||
KeyData.create(key=key, data=data)
|
||||
|
||||
def assertContains(self, obj, expected):
|
||||
contains = fn.json_contains(KeyData.data, json.dumps(obj))
|
||||
query = (KeyData
|
||||
.select(KeyData.key)
|
||||
.where(contains)
|
||||
.order_by(KeyData.key)
|
||||
.namedtuples())
|
||||
self.assertEqual([m.key for m in query], expected)
|
||||
|
||||
def test_json_contains(self):
|
||||
# Simple checks for key.
|
||||
self.assertContains('k1', ['a'])
|
||||
self.assertContains('k2', ['a', 'b'])
|
||||
self.assertContains('k3', ['a', 'b', 'c'])
|
||||
self.assertContains('kx', [])
|
||||
self.assertContains('y1', [])
|
||||
|
||||
# Partial dictionary.
|
||||
self.assertContains({'k1': 'v1'}, ['a'])
|
||||
self.assertContains({'k2': 'v2'}, ['a', 'b'])
|
||||
self.assertContains({'k3': 'v3'}, ['a', 'b', 'c'])
|
||||
self.assertContains({'k2': 'v2', 'k3': 'v3'}, ['a', 'b'])
|
||||
|
||||
self.assertContains({'k2': 'vx'}, [])
|
||||
self.assertContains({'k2': 'v2', 'k3': 'vx'}, [])
|
||||
self.assertContains({'y1': 'z1'}, [])
|
||||
|
||||
# List, interpreted as list of keys.
|
||||
self.assertContains(['k1', 'k2'], ['a'])
|
||||
self.assertContains(['k4'], ['b', 'd'])
|
||||
self.assertContains(['kx'], [])
|
||||
self.assertContains(['y1'], [])
|
||||
|
||||
# List, interpreted as ordered list of items.
|
||||
self.assertContains(['foo'], ['e'])
|
||||
self.assertContains(['foo', 'bar'], ['e'])
|
||||
self.assertContains(['bar', 'foo'], [])
|
||||
|
||||
# Nested dictionaries.
|
||||
self.assertContains({'x1': 'y1'}, ['c'])
|
||||
self.assertContains({'x1': ['y1']}, ['c'])
|
||||
self.assertContains({'x1': {'y1': 'z1'}}, ['c'])
|
||||
self.assertContains({'x1': {'y2': 'z2'}}, ['c', 'd'])
|
||||
self.assertContains({'x1': {'y2': 'z2'}, 'k4': 'v4'}, ['d'])
|
||||
|
||||
self.assertContains({'x1': {'yx': 'z1'}}, [])
|
||||
self.assertContains({'x1': {'y1': 'z1', 'y3': 'z3'}}, [])
|
||||
self.assertContains({'x1': {'y2': 'zx'}}, [])
|
||||
self.assertContains({'x1': {'k4': 'v4'}}, [])
|
||||
|
||||
# Mixing dictionaries and lists.
|
||||
self.assertContains({'x1': {'y2': 'z2', 'y3': [0]}}, ['d'])
|
||||
self.assertContains({'x1': {'y2': 'z2', 'y3': [0, 1, 2]}}, ['d'])
|
||||
|
||||
self.assertContains({'x1': {'y2': 'z2', 'y3': [0, 1, 2, 4]}}, [])
|
||||
self.assertContains({'x1': {'y2': 'z2', 'y3': [0, 2]}}, [])
|
||||
|
||||
|
||||
class CalendarMonth(TestModel):
|
||||
name = TextField()
|
||||
value = IntegerField()
|
||||
@@ -1829,7 +1753,7 @@ class TestSqliteReturning(ModelTestCase):
|
||||
|
||||
@skip_unless(database.server_version >= (3, 35, 0), 'sqlite returning clause required')
|
||||
class TestSqliteReturningConfig(ModelTestCase):
|
||||
database = SqliteExtDatabase(':memory:', returning_clause=True)
|
||||
database = SqliteDatabase(':memory:', returning_clause=True)
|
||||
requires = [KVR, User]
|
||||
|
||||
def test_pk_set_properly(self):
|
||||
|
||||
@@ -3,7 +3,6 @@ import datetime
|
||||
from peewee import *
|
||||
from playhouse.sqlite_changelog import ChangeLog
|
||||
from playhouse.sqlite_ext import JSONField
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
|
||||
from .base import ModelTestCase
|
||||
from .base import TestModel
|
||||
@@ -12,7 +11,7 @@ from .base import skip_unless
|
||||
from .sqlite_helpers import json_installed
|
||||
|
||||
|
||||
database = SqliteExtDatabase(':memory:', pragmas={'foreign_keys': 1})
|
||||
database = SqliteDatabase(':memory:', pragmas={'foreign_keys': 1})
|
||||
|
||||
|
||||
class Person(TestModel):
|
||||
|
||||
@@ -4,7 +4,6 @@ import random
|
||||
|
||||
from peewee import *
|
||||
from peewee import sqlite3
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
from playhouse.sqlite_udf import register_all
|
||||
|
||||
from .base import IS_SQLITE_9
|
||||
|
||||
Reference in New Issue
Block a user