Skip to content

Commit ec7b2ca

Browse files
authored
projections (#4)
* feature | projections * remove | prints * update | types map * update | init imports * update | tests gh action
1 parent 32e8dc3 commit ec7b2ca

File tree

17 files changed

+236
-13
lines changed

17 files changed

+236
-13
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ jobs:
88
matrix:
99
python-version: [ 3.8, 3.9, 3.10.5 ]
1010
poetry-version: [ 1.2.0 ]
11-
os: [ ubuntu-18.04 ]
12-
runs-on: ${{ matrix.os }}
11+
runs-on: ubuntu-latest
1312
steps:
1413
- uses: actions/checkout@v2
1514
- name: Build And Run DB
16-
run: scripts/build_and_run.sh
15+
run: docker run -d --init -p 10001:10001 -t romanright/annadb:0.2.0
1716
- uses: actions/setup-python@v2
1817
with:
1918
python-version: ${{ matrix.python-version }}

annadb/__init__.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
__version__ = "0.1.3"
1+
__version__ = "0.1.4"
22

33
__all__ = [
44
# Entities
55
"Connection",
66
# utils
77
"to_str",
88
# Operators
9+
# Update operators
910
"Inc",
1011
"Set",
12+
# Find operators
13+
# Comparison
14+
"Eq",
15+
"Neq",
16+
"Gt",
17+
"Lt",
18+
"Gte",
19+
"Lte",
20+
# Logical
21+
"And",
22+
"Or",
23+
"Not",
24+
# Projection operators
25+
"Keep",
26+
"keep",
1127
# Fields
1228
"root",
29+
# Constants
30+
"null",
1331
]
1432

1533
from annadb.connection import Connection
1634
from annadb.dump import to_str
17-
from annadb.query.path import root
35+
from annadb.query.find.operators import Eq, Neq, Gt, Lt, Gte, Lte, And, Or, Not
36+
from annadb.query.project.operators import Keep
1837
from annadb.query.update.operators import Inc, Set
38+
from annadb.data_types.constants import root, null, keep

annadb/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SORT_QUERY: str = "sort"
2222
OFFSET_QUERY: str = "offset"
2323
LIMIT_QUERY: str = "limit"
24+
PROJECT_QUERY: str = "project"
2425

2526
# FIND OPERATORS
2627
EQ_OPERATOR: str = "eq"
@@ -43,6 +44,9 @@
4344
ASC_OPERATOR: str = "asc"
4445
DESC_OPERATOR: str = "desc"
4546

47+
# PROJECT OPERATORS
48+
KEEP_OPERATOR: str = "keep"
49+
4650
# RESPONSE
4751
RESPONSE_OBJECTS: str = "objects"
4852
RESPONSE_IDS: str = "ids"

annadb/data_types/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from annadb import Keep
12
from annadb.data_types.primitive import Null
23
from annadb.query.path import Path
34

45
root = Path(None)
56
null = Null()
7+
keep = Keep()

annadb/data_types/types_map.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
QUERY_SET,
4444
LIMIT_QUERY,
4545
OFFSET_QUERY,
46+
KEEP_OPERATOR,
47+
PROJECT_QUERY,
4648
)
4749
from annadb.data_types.map import Map
4850
from annadb.data_types.primitive import (
@@ -58,6 +60,7 @@
5860
from annadb.data_types.vector import Vector
5961
from annadb.query.find.operators import Eq, Neq, Gt, Gte, Lt, Lte, And, Or, Not
6062
from annadb.query.path import Path
63+
from annadb.query.project.operators import Keep
6164
from annadb.query.query_set import QuerySet
6265
from annadb.query.sort.operators import Asc, Desc
6366
from annadb.query.types import (
@@ -68,7 +71,7 @@
6871
Delete,
6972
Sort,
7073
Limit,
71-
Offset,
74+
Offset, Project,
7275
)
7376
from annadb.query.update.operators import Set, Inc
7477
from annadb.response import (
@@ -106,6 +109,7 @@
106109
SORT_QUERY: Sort,
107110
LIMIT_QUERY: Limit,
108111
OFFSET_QUERY: Offset,
112+
PROJECT_QUERY: Project,
109113
# FIND OPERATORS
110114
EQ_OPERATOR: Eq,
111115
NEQ_OPERATOR: Neq,
@@ -122,6 +126,8 @@
122126
# SORT OPERATORS
123127
ASC_OPERATOR: Asc,
124128
DESC_OPERATOR: Desc,
129+
# PROJECTION OPERATORS
130+
KEEP_OPERATOR: Keep,
125131
# RESPONSE
126132
RESPONSE_OBJECTS: Objects,
127133
RESPONSE_IDS: IDs,

annadb/query/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ def update(self, *args):
5858
return UpdateQuery(
5959
*args, query_set=self.query_set, collection=self.collection
6060
)
61+
62+
def project(self, projection: dict):
63+
from annadb.query.project.query import ProjectQuery
64+
65+
return ProjectQuery(
66+
projection, query_set=self.query_set, collection=self.collection
67+
)

annadb/query/project/__init__.py

Whitespace-only changes.

annadb/query/project/operators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from annadb.constants import KEEP_OPERATOR
2+
from annadb.data_types.primitive import PrimitiveBase
3+
4+
5+
class Keep(PrimitiveBase):
6+
prefix = KEEP_OPERATOR
7+
instance_type = "keep"
8+
9+
def __init__(self, _=None):
10+
super(Keep, self).__init__(None)

annadb/query/project/query.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import typing
2+
3+
from annadb.query.base import BaseQuery
4+
from annadb.query.query_set import QuerySet
5+
from annadb.query.types import Project
6+
7+
if typing.TYPE_CHECKING:
8+
from annadb.collection import Collection
9+
10+
11+
class ProjectQuery(BaseQuery):
12+
def __init__(
13+
self,
14+
project_map: typing.Optional[dict],
15+
query_set: QuerySet,
16+
collection: "Collection"
17+
):
18+
self.collection = collection
19+
self.query_set = query_set
20+
self.query_set.push(Project(data=project_map))

annadb/query/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
UPDATE_QUERY,
77
OFFSET_QUERY,
88
LIMIT_QUERY,
9-
DELETE_QUERY,
9+
DELETE_QUERY, PROJECT_QUERY,
1010
)
11+
from annadb.data_types.map import MapUnique
1112
from annadb.data_types.modifier import ModifierBase
1213
from annadb.data_types.primitive import PrimitiveBase
1314
from annadb.data_types.vector import VectorBase
@@ -46,3 +47,7 @@ class Delete(PrimitiveBase):
4647

4748
def __init__(self, _=None):
4849
super(Delete, self).__init__(None)
50+
51+
52+
class Project(MapUnique):
53+
prefix = PROJECT_QUERY

0 commit comments

Comments
 (0)