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

Add DB3Document and support add document operation and new-db #302

Merged
merged 6 commits into from
Feb 6, 2023

Conversation

jingchen2222
Copy link
Collaborator

@jingchen2222 jingchen2222 commented Feb 3, 2023

This is a part of work from #271

In this PR, we are going to create a document

  • support create document using command-cli new-db --addr db_addr --collection-name collection_name --documents document_list

  • support create document without index

  • support get document using DocumentId
    Given the limit of the PR size, we will implement further document operation including create documents and get document using index/key in the future PR.

  • Add DocumentId and support add document id, tx id, owner via DB3Document

  • Put index entry for collection indexes.

  • CLI command change: collection-id --> collection-name

CMD demo

db3>-$ init
Init key successfully!

db3>-$ show-key
 address                                    | scheme
--------------------------------------------+-----------
 0x84b0bd55e7ad979b7cb92a56f561190de8f68403 | secp256k1


db3>-$ new-db
 database address                           | transaction id
--------------------------------------------+----------------------------------------------
 0xc41e371402b1610fd934d76f2c2576db96bbb2bc | q3TJ4waMZB5kBSTO/i5D+HWs7lj+F1t8UMywWytTY6c=

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

db3>-$ show-collection --addr 0x997f631fcafeed5ee319c83683ae16e64783602b
 name  | index
-------+----------------------------------------------------------------------------------
 books | {"name":"idx1","id":1,"fields":[{"field_path":"name","value_mode":{"Order":1}}]}

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


@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2023

Codecov Report

Merging #302 (6e72c3b) into main (2a7edee) will increase coverage by 5.67%.
The diff coverage is 83.41%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #302      +/-   ##
==========================================
+ Coverage   48.59%   54.26%   +5.67%     
==========================================
  Files          55       56       +1     
  Lines        4834     5613     +779     
==========================================
+ Hits         2349     3046     +697     
- Misses       2485     2567      +82     
Flag Coverage Δ
rust 54.26% <83.41%> (+5.67%) ⬆️

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

Impacted Files Coverage Δ
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.98% <0.00%> (-0.07%) ⬇️
src/crypto/src/id.rs 77.66% <72.50%> (+17.20%) ⬆️
src/storage/src/db_store.rs 76.55% <83.88%> (+13.70%) ⬆️
src/crypto/src/db3_document.rs 98.78% <98.78%> (ø)
src/crypto/src/db3_address.rs 45.45% <0.00%> (+13.63%) ⬆️

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

src/base/src/db3_document.rs Outdated Show resolved Hide resolved
src/base/src/db3_document.rs Outdated Show resolved Hide resolved
src/base/src/db3_document.rs Outdated Show resolved Hide resolved
src/node/src/abci_impl.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
src/base/src/db3_document.rs Outdated Show resolved Hide resolved
1. use snake case for argument naming
2. make add_owner and add_document_id non public
src/storage/src/db_store.rs Outdated Show resolved Hide resolved
@@ -64,6 +66,9 @@ impl TxId {
pub fn to_base64(&self) -> String {
base64ct::Base64::encode_string(self.as_ref())
}
pub fn try_from_base64(input: &str) -> std::result::Result<Self, DB3Error> {
Self::try_from_bytes(base64ct::Base64::decode_vec(input).unwrap().as_slice())
Copy link
Contributor

Choose a reason for hiding this comment

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

replace unwrap() with map_err

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will fix in next pr.

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 f5ed141 into main Feb 6, 2023
@imotai imotai deleted the feat/create_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.

None yet

4 participants