Skip to content

Commit 33a6b75

Browse files
Feat/nosv (#14)
* Removed use of SV functions * Aligned with immudb schema without SV, refactored directory layout * Added Scan and Reference methods
1 parent 40743eb commit 33a6b75

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+912
-1289
lines changed

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[run]
22
source = immudb
3-
omit = immudb/service/*,immudb/schema/*
3+
omit = immudb/grpc/*
44

55
[report]
6-
omit = immudb/service/*,immudb/schema/*
6+
omit = immudb/grpc/*

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ __pycache__/
44
*.vscode
55
rootfile
66
.coverage
7+
bin/
8+
build/
9+
dist/
10+
immudb_py.egg-info/
11+
lib/

Makefile

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
SHELL := /bin/bash
22

3-
PROTOC ?= $(shell which protoc)
4-
GRPC_PYTHON_PLUGIN ?= $(shell which grpc_python_plugin)
3+
54
PYTEST ?= python -m pytest
65
PIP ?= pip
76
COVERAGE ?= $(shell which coverage)
87

9-
PROTO_DIR := proto
10-
PROTO_FILE := ${PROTO_DIR}/schema.proto
11-
PROTO_URL := https://raw.githubusercontent.com/codenotary/immudb/master/pkg/api/schema/schema.proto
12-
13-
SCHEMA_OUT_DIR := immudb/schema
14-
GRPC_OUT_DIR := immudb/service
8+
all: init test
159

16-
17-
.PHONY: ${PROTO_DIR}
18-
${PROTO_DIR}:
19-
${PROTOC} -I ${PROTO_DIR} ${PROTO_FILE} \
20-
--python_out=${SCHEMA_OUT_DIR} \
21-
--grpc_out=${GRPC_OUT_DIR} \
22-
--plugin=protoc-gen-grpc=${GRPC_PYTHON_PLUGIN}
10+
proto: immudb/grpc
11+
make -C immudb/grpc
2312

2413
init:
2514
$(PIP) install -r requirements.txt --user

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ read or write operation:
146146

147147
### Multi-key read and write
148148

149-
Transactional multi-key read and write operations are supported by immudb and immupy.
149+
Transactional multi-key read and write operations are supported by immudb and immudb-py.
150150
Atomic multi-key write (all entries are persisted or none):
151151

152152
```python

devtest.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
a.login("immudb","immudb")
66
print(a.databaseUse(b"defaultdb"))
77
#print(a.databaseCreate(b"testdb"))
8-
print(a.databaseList())
9-
print("Use:")
10-
print(a.databaseUse(b"defaultdb"))
8+
#print(a.databaseList())
9+
#print("Use:")
10+
#print(a.databaseUse(b"defaultdb"))
1111

1212
# print(a.databaseUse(b"testdb"))
1313

@@ -25,6 +25,10 @@
2525
# print(resp)
2626

2727

28-
xset = {b"key1": b"value1", b"key2": b"value2"}
29-
print(a.setAll(xset))
30-
print(a.getAll(xset.keys()))
28+
#xset = {b"key3": b"value3", b"key4": b"value4"}
29+
#print(a.setAll(xset))
30+
#print(a.getAll(xset.keys()))
31+
32+
#print(a.safeSet(b'keykey2', b'valval2'))
33+
#print(a.get(b'keykey2'))
34+
print(a.history(b'key1'))

immudb/client.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
get, listUsers, safeGet, safeSet, setValue, history,
88
scan, reference)
99
from immudb.rootService import RootService
10-
from immudb.service import schema_pb2_grpc
10+
from immudb.grpc import schema_pb2_grpc
1111

12+
OLDEST_FIRST=True
13+
NEWEST_FIRST=False
1214

1315
class ImmudbClient:
1416
def __init__(self, immudUrl=None):
@@ -97,7 +99,7 @@ def getAll(self, keys: list):
9799
klist = [schema_pb2_grpc.schema__pb2.Key(key=k) for k in keys]
98100
request = schema_pb2_grpc.schema__pb2.KeyList(keys=klist)
99101
resp = batchGet.call(self.__stub, self.__rs, request)
100-
return {i.key: i.value.payload for i in resp.itemlist.items}
102+
return resp
101103

102104
def setAll(self, kv: dict):
103105
_KVs = []
@@ -146,8 +148,13 @@ def databaseCreate(self, dbName: bytes):
146148
def currentRoot(self):
147149
return currentRoot.call(self.__stub, self.__rs, None)
148150

149-
def history(self, key: bytes):
150-
request = schema_pb2_grpc.schema__pb2.Key(key=key)
151+
def history(self, key: bytes, offset: int, limit: int, sortorder: bool):
152+
request = schema_pb2_grpc.schema__pb2.HistoryOptions(
153+
key=key,
154+
offset=offset,
155+
limit=limit,
156+
reverse=sortorder
157+
)
151158
return history.call(self.__stub, self.__rs, request)
152159

153160
def logout(self):
@@ -179,3 +186,24 @@ def zscan(self):
179186

180187

181188

189+
def scan(self, prefix: bytes, offset: bytes, limit:int=10, reverse:bool=False, deep:bool=False):
190+
request = schema_pb2_grpc.schema__pb2.ScanOptions(
191+
prefix=prefix,
192+
offset=offset,
193+
limit=limit,
194+
reverse=reverse,
195+
deep=deep)
196+
return scan.call(self.__stub, self.__rs, request)
197+
198+
def reference(self, refkey: bytes, key: bytes):
199+
request = schema_pb2_grpc.schema__pb2.ReferenceOptions(
200+
reference = refkey,
201+
key=key
202+
)
203+
return reference.call(self.__stub, self.__rs, request)
204+
205+
def zadd(self):
206+
pass
207+
208+
def zscan(self):
209+
pass

immudb/consistency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hashlib
22

3-
from immudb.schema import schema_pb2
3+
from immudb.grpc import schema_pb2
44
from immudb import constants
55

66

immudb/grpc/Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
SHELL := /bin/bash
2+
3+
PROTOC ?= $(shell which protoc)
4+
GRPC_PYTHON_PLUGIN ?= $(shell which grpc_python_plugin)
5+
PYTEST ?= python -m pytest
6+
PIP ?= pip
7+
COVERAGE ?= $(shell which coverage)
8+
9+
PROTO_DIR := proto
10+
PROTO_FILE := ${PROTO_DIR}/schema.proto
11+
PROTO_URL := https://raw.githubusercontent.com/codenotary/immudb/master/pkg/api/schema/schema.proto
12+
13+
SCHEMA_OUT_DIR := immudb/schema
14+
GRPC_OUT_DIR := immudb/service
15+
GOPATH ?= ${HOME}/go
16+
PROTOC_INCLUDE_PATH := \-I${GOPATH}/pkg/mod \
17+
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
18+
-I${GOPATH}/pkg/mod/github.com/dgraph-io/badger/[email protected] \
19+
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected] \
20+
-I${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/protoc-gen-swagger
21+
22+
.PHONY: ${PROTO_DIR}
23+
${PROTO_DIR}:
24+
${PROTOC} -I${PROTO_DIR} ${PROTOC_INCLUDE_PATH} \
25+
${PROTO_FILE} \
26+
--python_out=. --grpc_out=. \
27+
--plugin=protoc-gen-grpc=/home/simone/sw/immu-py/bin/grpc_python_plugin
28+
29+
30+
# python3 -m grpc_tools.protoc \
31+
# ${PROTOC_INCLUDE_PATH} \
32+
# ${PROTO_FILE} \
33+
# --python_out=. \
34+
# --grpc_python_out=.
35+
# python3 -m grpc_tools.protoc \
36+
# ${PROTOC_INCLUDE_PATH} \
37+
# ${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/protoc-gen-swagger/options/annotations.proto \
38+
# --python_out=. \
39+
# --grpc_python_out=.
40+
# python3 -m grpc_tools.protoc \
41+
# ${PROTOC_INCLUDE_PATH} \
42+
# ${GOPATH}/pkg/mod/github.com/grpc-ecosystem/[email protected]/protoc-gen-swagger/options/openapiv2.proto \
43+
# --python_out=. \
44+
# --grpc_python_out=.
45+
./fixup.sh
46+
47+
init:
48+
$(PIP) install -r requirements.txt --user
49+
50+
dev:
51+
$(PIP) install -r requirements-dev.txt --user
52+
53+
test:
54+
$(PYTEST) -vv --color=yes tests/
55+
56+
coverage:
57+
$(COVERAGE) run -m pytest tests
58+
59+
install:
60+
python setup.py install
61+
62+
.PHONY: dist
63+
dist:
64+
mkdir -p ./dist
65+
rm ./dist/*
66+
python setup.py sdist bdist_wheel
File renamed without changes.

immudb/grpc/fixup.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
sed -i -r 's/^import (.+_pb2.*)/from . import \1/g' *_pb2*.py

0 commit comments

Comments
 (0)