Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support list documents api and show-doc command cli #306

Merged
merged 10 commits into from
Feb 8, 2023

Conversation

jingchen2222
Copy link
Collaborator

@jingchen2222 jingchen2222 commented Feb 7, 2023

Features

  • add rpc ListDocuments() api
  • support list_documents in db_store
  • support show-doc command cli
  • separate docId, txId, owner from document content. pretty print document in the console.
  • Move db3_document to storage

Demo

❯ ./target/debug/db3 console                                                                                                                                                   ─╯

██████╗ ██████╗ ██████╗
██╔══██╗██╔══██╗╚════██╗
██║  ██║██████╔╝ █████╔╝
██║  ██║██╔══██╗ ╚═══██╗
██████╔╝██████╔╝██████╔╝
╚═════╝ ╚═════╝ ╚═════╝
@db3.network🚀🚀🚀
db3>-$ init
Init key successfully!
db3>-$ new-db
 database address                           | transaction id
--------------------------------------------+----------------------------------------------
 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e | ztTsONVnf/hy4sPavIo8d/fh+u3Epg15lKjMosZbLJY=

db3>-$ new-collection --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e --name books --index '{"id":1,"name":"idx1","fields":[{"field_path":"name","value_mode":{"Order":1}}]}'
send add collection done with tx
HjNiRxa0wX6YECil4XkOU+rggaxGlpDtsRmm0Ku3DI8=

db3>-$ new-collection --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e --name student --index '{"id":1,"name":"idx1","fields":[{"field_path":"age","value_mode":{"Order":1}}]}'
send add collection done with tx
mWAx1YYBRavusa3SbUCxnumfuCbhQ49ysr/zKEkBefk=

db3>-$ new-doc --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e --collection-name books --documents '{"name": "John Doe","age": 43,"phones": ["+44 1234567","+44 2345678"]}'
send add document done with tx
k/DSFW7wvGGE3YDNxg8JDW5/Q/RXBjWZWQG8k3tsj4Q=

db3>-$ show-doc --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e  --collection-name books
 id_base64                                    | owner                                      | document
----------------------------------------------+--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------
 AQAAAAAAAAAyAAAAAQAAAAEAAAAAAAAAfAAAAAEAAAAA | 0x84b0bd55e7ad979b7cb92a56f561190de8f68403 | Document({"name": String("John Doe"), "age": Int64(43), "phones": Array([String("+44 1234567"), String("+44 2345678")])})

db3>-$ new-doc --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e --collection-name books --documents '{"name": "John Doe","age": 44,"phones": ["+44 1234567","+44 2345678"]}'
send add document done with tx
gN5C8SmRDOT1BdDjSbNvjVOqBUdIKjikQSNDm04Ix+o=


db3>-$ new-doc --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e --collection-name books --documents '{"name": "John Doe","age": 45,"phones": ["+44 1234567","+44 2345678"]}'
send add document done with tx
dGsZr0iu+882cCu/yY/d+78ML+GwLrQfe6uV9+rbD08=


db3>-$ show-doc --addr 0x22fb51848e26b34e242dd16a1224e8f23ee9b42e  --collection-name books
 id_base64                                    | owner                                      | document
----------------------------------------------+--------------------------------------------+---------------------------------------------------------------------------------------------------------------------------
 AQAAAAAAAAAyAAAAAQAAAAEAAAAAAAAAfAAAAAEAAAAA | 0x84b0bd55e7ad979b7cb92a56f561190de8f68403 | Document({"name": String("John Doe"), "age": Int64(43), "phones": Array([String("+44 1234567"), String("+44 2345678")])})
 AQAAAAAAAAAyAAAAAQAAAAEAAAAAAAABLAAAAAEAAAAA | 0x84b0bd55e7ad979b7cb92a56f561190de8f68403 | Document({"name": String("John Doe"), "age": Int64(44), "phones": Array([String("+44 1234567"), String("+44 2345678")])})
 AQAAAAAAAAAyAAAAAQAAAAEAAAAAAAABPgAAAAEAAAAA | 0x84b0bd55e7ad979b7cb92a56f561190de8f68403 | Document({"name": String("John Doe"), "age": Int64(45), "phones": Array([String("+44 1234567"), String("+44 2345678")])})

@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Merging #306 (224c4f5) into main (6c8c8b6) will increase coverage by 1.37%.
The diff coverage is 72.98%.

@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
+ Coverage   54.67%   56.05%   +1.37%     
==========================================
  Files          56       57       +1     
  Lines        5668     5991     +323     
==========================================
+ Hits         3099     3358     +259     
- Misses       2569     2633      +64     
Flag Coverage Δ
rust 56.05% <72.98%> (+1.37%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/base/src/lib.rs 100.00% <ø> (ø)
src/cmd/src/command.rs 0.00% <0.00%> (ø)
src/crypto/src/lib.rs 100.00% <ø> (ø)
src/error/src/lib.rs 100.00% <ø> (ø)
src/node/src/auth_storage.rs 0.97% <0.00%> (-0.02%) ⬇️
src/node/src/storage_node_impl.rs 0.52% <0.00%> (-0.09%) ⬇️
src/sdk/src/store_sdk.rs 83.49% <0.00%> (-4.34%) ⬇️
src/storage/src/lib.rs 100.00% <ø> (ø)
src/crypto/src/id.rs 93.37% <93.51%> (+15.44%) ⬆️
src/storage/src/db3_document.rs 97.86% <97.56%> (ø)
... and 5 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

src/cmd/src/command.rs Outdated Show resolved Hide resolved
…eat/get_document

# Conflicts:
#	src/crypto/src/db3_document.rs
@github-actions github-actions bot added the S-kv label Feb 8, 2023
@jingchen2222
Copy link
Collaborator Author

jingchen2222 commented Feb 8, 2023

@imotai PR is ready to be merged

Copy link
Contributor

@imotai imotai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@imotai imotai merged commit b16b47a into main Feb 8, 2023
@imotai imotai deleted the feat/get_document branch February 14, 2023 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WIP: propose the document level ownership
3 participants