zlmdb 25.12.2__cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zlmdb/__init__.py +416 -0
- zlmdb/_database.py +990 -0
- zlmdb/_errors.py +31 -0
- zlmdb/_flatc/__init__.py +105 -0
- zlmdb/_lmdb_vendor/__init__.py +37 -0
- zlmdb/_lmdb_vendor/__main__.py +25 -0
- zlmdb/_lmdb_vendor/_config.py +10 -0
- zlmdb/_lmdb_vendor/_lmdb_cffi.cpython-314t-aarch64-linux-gnu.so +0 -0
- zlmdb/_lmdb_vendor/cffi.py +2606 -0
- zlmdb/_lmdb_vendor/tool.py +670 -0
- zlmdb/_meta.py +27 -0
- zlmdb/_pmap.py +1667 -0
- zlmdb/_schema.py +137 -0
- zlmdb/_transaction.py +181 -0
- zlmdb/_types.py +1596 -0
- zlmdb/_version.py +27 -0
- zlmdb/cli.py +41 -0
- zlmdb/flatbuffers/__init__.py +60 -0
- zlmdb/flatbuffers/_git_version.py +24 -0
- zlmdb/flatbuffers/_version.py +17 -0
- zlmdb/flatbuffers/builder.py +824 -0
- zlmdb/flatbuffers/compat.py +89 -0
- zlmdb/flatbuffers/encode.py +43 -0
- zlmdb/flatbuffers/flexbuffers.py +1570 -0
- zlmdb/flatbuffers/number_types.py +182 -0
- zlmdb/flatbuffers/packer.py +42 -0
- zlmdb/flatbuffers/reflection/AdvancedFeatures.py +10 -0
- zlmdb/flatbuffers/reflection/BaseType.py +25 -0
- zlmdb/flatbuffers/reflection/Enum.py +252 -0
- zlmdb/flatbuffers/reflection/EnumVal.py +144 -0
- zlmdb/flatbuffers/reflection/Field.py +325 -0
- zlmdb/flatbuffers/reflection/KeyValue.py +84 -0
- zlmdb/flatbuffers/reflection/Object.py +260 -0
- zlmdb/flatbuffers/reflection/RPCCall.py +195 -0
- zlmdb/flatbuffers/reflection/Schema.py +301 -0
- zlmdb/flatbuffers/reflection/SchemaFile.py +112 -0
- zlmdb/flatbuffers/reflection/Service.py +213 -0
- zlmdb/flatbuffers/reflection/Type.py +148 -0
- zlmdb/flatbuffers/reflection/__init__.py +0 -0
- zlmdb/flatbuffers/reflection.fbs +156 -0
- zlmdb/flatbuffers/table.py +129 -0
- zlmdb/flatbuffers/util.py +47 -0
- zlmdb/py.typed +0 -0
- zlmdb/tests/conftest.py +9 -0
- zlmdb/tests/lmdb/__init__.py +0 -0
- zlmdb/tests/lmdb/address_book.py +287 -0
- zlmdb/tests/lmdb/crash_test.py +339 -0
- zlmdb/tests/lmdb/cursor_test.py +333 -0
- zlmdb/tests/lmdb/env_test.py +919 -0
- zlmdb/tests/lmdb/getmulti_test.py +92 -0
- zlmdb/tests/lmdb/iteration_test.py +258 -0
- zlmdb/tests/lmdb/package_test.py +70 -0
- zlmdb/tests/lmdb/test_lmdb.py +188 -0
- zlmdb/tests/lmdb/testlib.py +185 -0
- zlmdb/tests/lmdb/tool_test.py +60 -0
- zlmdb/tests/lmdb/txn_test.py +575 -0
- zlmdb/tests/orm/MNodeLog.py +853 -0
- zlmdb/tests/orm/__init__.py +0 -0
- zlmdb/tests/orm/_schema_fbs.py +215 -0
- zlmdb/tests/orm/_schema_mnode_log.py +1202 -0
- zlmdb/tests/orm/_schema_py2.py +250 -0
- zlmdb/tests/orm/_schema_py3.py +307 -0
- zlmdb/tests/orm/_test_flatbuffers.py +144 -0
- zlmdb/tests/orm/_test_serialization.py +144 -0
- zlmdb/tests/orm/test_basic.py +217 -0
- zlmdb/tests/orm/test_etcd.py +275 -0
- zlmdb/tests/orm/test_pmap_indexes.py +466 -0
- zlmdb/tests/orm/test_pmap_types.py +90 -0
- zlmdb/tests/orm/test_pmaps.py +295 -0
- zlmdb/tests/orm/test_select.py +619 -0
- zlmdb-25.12.2.dist-info/METADATA +280 -0
- zlmdb-25.12.2.dist-info/RECORD +76 -0
- zlmdb-25.12.2.dist-info/WHEEL +7 -0
- zlmdb-25.12.2.dist-info/entry_points.txt +3 -0
- zlmdb-25.12.2.dist-info/licenses/LICENSE +167 -0
- zlmdb-25.12.2.dist-info/licenses/NOTICE +41 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
###############################################################################
|
|
2
|
+
#
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) typedef int GmbH
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in
|
|
15
|
+
# all copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
# THE SOFTWARE.
|
|
24
|
+
#
|
|
25
|
+
###############################################################################
|
|
26
|
+
|
|
27
|
+
import os
|
|
28
|
+
import sys
|
|
29
|
+
import pytest
|
|
30
|
+
import logging
|
|
31
|
+
|
|
32
|
+
import txaio
|
|
33
|
+
|
|
34
|
+
txaio.use_twisted()
|
|
35
|
+
|
|
36
|
+
import zlmdb # noqa
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
from tempfile import TemporaryDirectory
|
|
40
|
+
except ImportError:
|
|
41
|
+
from backports.tempfile import TemporaryDirectory # type:ignore
|
|
42
|
+
|
|
43
|
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
44
|
+
|
|
45
|
+
if sys.version_info >= (3, 6):
|
|
46
|
+
from _schema_py3 import User, Schema1, Schema3, Schema4
|
|
47
|
+
else:
|
|
48
|
+
from _schema_py2 import User, Schema1, Schema3, Schema4
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@pytest.fixture(scope="module")
|
|
52
|
+
def testset1():
|
|
53
|
+
users = []
|
|
54
|
+
for j in range(10):
|
|
55
|
+
for i in range(100):
|
|
56
|
+
user = User.create_test_user(oid=j * 100 + i, realm_oid=j)
|
|
57
|
+
users.append(user)
|
|
58
|
+
return users
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_truncate_table():
|
|
62
|
+
with TemporaryDirectory() as dbpath:
|
|
63
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
64
|
+
|
|
65
|
+
schema = Schema1()
|
|
66
|
+
|
|
67
|
+
stats = zlmdb.TransactionStats()
|
|
68
|
+
tabs = [
|
|
69
|
+
schema.tab_oid_json,
|
|
70
|
+
schema.tab_str_json,
|
|
71
|
+
schema.tab_uuid_json,
|
|
72
|
+
schema.tab_oid_cbor,
|
|
73
|
+
schema.tab_str_cbor,
|
|
74
|
+
schema.tab_uuid_cbor,
|
|
75
|
+
schema.tab_oid_pickle,
|
|
76
|
+
schema.tab_str_pickle,
|
|
77
|
+
schema.tab_uuid_pickle,
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
with zlmdb.Database(dbpath) as db:
|
|
81
|
+
with db.begin(write=True, stats=stats) as txn:
|
|
82
|
+
for tab in tabs:
|
|
83
|
+
tab.truncate(txn)
|
|
84
|
+
|
|
85
|
+
logging.info(stats.puts)
|
|
86
|
+
logging.info(stats.dels)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_fill_check(testset1):
|
|
90
|
+
with TemporaryDirectory() as dbpath:
|
|
91
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
92
|
+
|
|
93
|
+
schema = Schema3()
|
|
94
|
+
|
|
95
|
+
with zlmdb.Database(dbpath) as db:
|
|
96
|
+
with db.begin(write=True) as txn:
|
|
97
|
+
for user in testset1:
|
|
98
|
+
schema.users[txn, user.authid] = user
|
|
99
|
+
|
|
100
|
+
with zlmdb.Database(dbpath) as db:
|
|
101
|
+
with db.begin() as txn:
|
|
102
|
+
for user in testset1:
|
|
103
|
+
_user = schema.users[txn, user.authid]
|
|
104
|
+
assert _user
|
|
105
|
+
assert _user == user
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_fill_check2(testset1):
|
|
109
|
+
with TemporaryDirectory() as dbpath:
|
|
110
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
111
|
+
|
|
112
|
+
schema = Schema4()
|
|
113
|
+
|
|
114
|
+
with zlmdb.Database(dbpath) as db:
|
|
115
|
+
with db.begin(write=True) as txn:
|
|
116
|
+
for user in testset1:
|
|
117
|
+
schema.users[txn, user.oid] = user
|
|
118
|
+
|
|
119
|
+
with zlmdb.Database(dbpath) as db:
|
|
120
|
+
with db.begin() as txn:
|
|
121
|
+
for user in testset1:
|
|
122
|
+
_user = schema.users[txn, user.oid]
|
|
123
|
+
assert _user
|
|
124
|
+
assert _user == user
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_select(testset1):
|
|
128
|
+
testset1_keys = set([user.authid for user in testset1])
|
|
129
|
+
|
|
130
|
+
with TemporaryDirectory() as dbpath:
|
|
131
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
132
|
+
|
|
133
|
+
schema = Schema3()
|
|
134
|
+
|
|
135
|
+
with zlmdb.Database(dbpath) as db:
|
|
136
|
+
with db.begin(write=True) as txn:
|
|
137
|
+
for user in testset1:
|
|
138
|
+
schema.users[txn, user.authid] = user
|
|
139
|
+
|
|
140
|
+
with zlmdb.Database(dbpath) as db:
|
|
141
|
+
with db.begin() as txn:
|
|
142
|
+
i = 0
|
|
143
|
+
for authid, user in schema.users.select(txn):
|
|
144
|
+
i += 1
|
|
145
|
+
assert user
|
|
146
|
+
assert authid == user.authid
|
|
147
|
+
assert authid in testset1_keys
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_count_all(testset1):
|
|
151
|
+
with TemporaryDirectory() as dbpath:
|
|
152
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
153
|
+
|
|
154
|
+
schema = Schema3()
|
|
155
|
+
|
|
156
|
+
with zlmdb.Database(dbpath) as db:
|
|
157
|
+
# count on empty table
|
|
158
|
+
with db.begin() as txn:
|
|
159
|
+
cnt = schema.users.count(txn)
|
|
160
|
+
assert cnt == 0
|
|
161
|
+
|
|
162
|
+
# fill (and count on each insert)
|
|
163
|
+
with db.begin(write=True) as txn:
|
|
164
|
+
i = 0
|
|
165
|
+
for user in testset1:
|
|
166
|
+
schema.users[txn, user.authid] = user
|
|
167
|
+
i += 1
|
|
168
|
+
|
|
169
|
+
# table count within filling transaction
|
|
170
|
+
cnt = schema.users.count(txn)
|
|
171
|
+
assert cnt == i
|
|
172
|
+
|
|
173
|
+
# table count within transaction
|
|
174
|
+
cnt = schema.users.count(txn)
|
|
175
|
+
assert cnt == len(testset1)
|
|
176
|
+
|
|
177
|
+
# table count in new transaction
|
|
178
|
+
with db.begin() as txn:
|
|
179
|
+
cnt = schema.users.count(txn)
|
|
180
|
+
assert cnt == len(testset1)
|
|
181
|
+
|
|
182
|
+
# table count in new connection
|
|
183
|
+
with zlmdb.Database(dbpath) as db:
|
|
184
|
+
with db.begin() as txn:
|
|
185
|
+
cnt = schema.users.count(txn)
|
|
186
|
+
assert cnt == len(testset1)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def test_count_prefix(testset1):
|
|
190
|
+
with TemporaryDirectory() as dbpath:
|
|
191
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
192
|
+
|
|
193
|
+
schema = Schema3()
|
|
194
|
+
|
|
195
|
+
with zlmdb.Database(dbpath) as db:
|
|
196
|
+
with db.begin(write=True) as txn:
|
|
197
|
+
for user in testset1:
|
|
198
|
+
schema.users[txn, user.authid] = user
|
|
199
|
+
|
|
200
|
+
n = len(testset1)
|
|
201
|
+
tests = [
|
|
202
|
+
(None, n),
|
|
203
|
+
("", n),
|
|
204
|
+
("test-", n),
|
|
205
|
+
("test-1", 111),
|
|
206
|
+
("test-11", 11),
|
|
207
|
+
("test-111", 1),
|
|
208
|
+
]
|
|
209
|
+
with zlmdb.Database(dbpath) as db:
|
|
210
|
+
with db.begin() as txn:
|
|
211
|
+
for prefix, num in tests:
|
|
212
|
+
cnt = schema.users.count(txn, prefix)
|
|
213
|
+
assert cnt == num
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_fill_with_indexes(testset1):
|
|
217
|
+
with TemporaryDirectory() as dbpath:
|
|
218
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
219
|
+
|
|
220
|
+
schema = Schema4()
|
|
221
|
+
|
|
222
|
+
with zlmdb.Database(dbpath) as db:
|
|
223
|
+
stats = zlmdb.TransactionStats()
|
|
224
|
+
|
|
225
|
+
with db.begin(write=True, stats=stats) as txn:
|
|
226
|
+
for user in testset1:
|
|
227
|
+
schema.users[txn, user.oid] = user
|
|
228
|
+
|
|
229
|
+
# check indexes has been written to (in addition to the table itself)
|
|
230
|
+
num_indexes = len(schema.users.indexes())
|
|
231
|
+
assert stats.puts == len(testset1) * (1 + num_indexes)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_truncate_table_with_index(testset1):
|
|
235
|
+
with TemporaryDirectory() as dbpath:
|
|
236
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
237
|
+
|
|
238
|
+
schema = Schema4()
|
|
239
|
+
|
|
240
|
+
with zlmdb.Database(dbpath) as db:
|
|
241
|
+
with db.begin(write=True) as txn:
|
|
242
|
+
for user in testset1:
|
|
243
|
+
schema.users[txn, user.oid] = user
|
|
244
|
+
|
|
245
|
+
stats = zlmdb.TransactionStats()
|
|
246
|
+
|
|
247
|
+
with zlmdb.Database(dbpath) as db:
|
|
248
|
+
with db.begin(write=True, stats=stats) as txn:
|
|
249
|
+
records = schema.users.truncate(txn)
|
|
250
|
+
logging.info("table truncated: {}".format(records))
|
|
251
|
+
|
|
252
|
+
logging.info(stats.puts)
|
|
253
|
+
logging.info(stats.dels)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def test_rebuild_index(testset1):
|
|
257
|
+
with TemporaryDirectory() as dbpath:
|
|
258
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
259
|
+
|
|
260
|
+
schema = Schema4()
|
|
261
|
+
|
|
262
|
+
with zlmdb.Database(dbpath) as db:
|
|
263
|
+
with db.begin(write=True) as txn:
|
|
264
|
+
for user in testset1:
|
|
265
|
+
schema.users[txn, user.oid] = user
|
|
266
|
+
|
|
267
|
+
with zlmdb.Database(dbpath) as db:
|
|
268
|
+
with db.begin(write=True) as txn:
|
|
269
|
+
records = schema.users.rebuild_index(txn, "idx1")
|
|
270
|
+
logging.info(
|
|
271
|
+
'\nrebuilt specific index "idx1" on "users": {} records affected'.format(
|
|
272
|
+
records
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def test_rebuild_all_indexes(testset1):
|
|
278
|
+
with TemporaryDirectory() as dbpath:
|
|
279
|
+
logging.info("Using temporary directory {} for database".format(dbpath))
|
|
280
|
+
|
|
281
|
+
schema = Schema4()
|
|
282
|
+
|
|
283
|
+
with zlmdb.Database(dbpath) as db:
|
|
284
|
+
with db.begin(write=True) as txn:
|
|
285
|
+
for user in testset1:
|
|
286
|
+
schema.users[txn, user.oid] = user
|
|
287
|
+
|
|
288
|
+
with zlmdb.Database(dbpath) as db:
|
|
289
|
+
with db.begin(write=True) as txn:
|
|
290
|
+
records = schema.users.rebuild_indexes(txn)
|
|
291
|
+
logging.info(
|
|
292
|
+
'\nrebuilt all indexes on "users": {} records affected'.format(
|
|
293
|
+
records
|
|
294
|
+
)
|
|
295
|
+
)
|