forked from bluesky/tiled
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_indexes.py
49 lines (40 loc) · 1.51 KB
/
json_indexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import asyncio
from tiled._tests.test_catalog import temp_postgres
from tiled.catalog.adapter import Adapter
from tiled.catalog.explain import record_explanations
from tiled.queries import Key
async def test(a):
for i in range(100):
await a.create_container(
metadata={
"number": i,
"number_as_string": str(i),
"nested": {"number": i, "number_as_string": str(i)},
},
specs=[],
structure_family="array",
)
# await a.create_metadata_index("nested_number_as_string", "nested.number_as_string")
# await a.create_metadata_index("nested_number", "nested.number")
with record_explanations() as e:
results = await a.search(Key("number_as_string") == "3").keys_slice(0, 5, 1)
assert len(results) == 1
results = await a.search(Key("number") == 3).keys_slice(0, 5, 1)
assert len(results) == 1
results = await a.search(Key("nested.number_as_string") == "3").keys_slice(
0, 5, 1
)
assert len(results) == 1
results = await a.search(Key("nested.number") == 3).keys_slice(0, 5, 1)
assert len(results) == 1
print(e)
async def test_sqlite():
async with Adapter.async_in_memory(echo=True) as a:
await test(a)
async def test_postgres():
async with temp_postgres(
"postgresql+asyncpg://postgres:secret@localhost:5432", echo=True
) as a:
await test(a)
# asyncio.run(test_postgres())
asyncio.run(test_sqlite())