Reading and inserting data

The format for writing and reading data is the same both in Set and VerifiedSet, just as it is for reading data both in both Get and VerifiedGet.

The only difference is that VerifiedSet returns proofs needed to mathematically verify that the data was not tampered. Note that generating that proof has a slight performance impact, so primitives are allowed without the proof. It is still possible get the proofs for a specific item at any time, so the decision about when or how frequently to do checks (with the Verify version of a method) is completely up to the user. It’s possible also to use dedicated auditors to ensure the database consistency, but the pattern in which every client is also an auditor is the more interesting one.

Get and set

  1. tx, err = client.Set(ctx, []byte(`hello`), []byte(`immutable world`))
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. fmt.Printf("Successfully committed tx %d\n", tx.Id)
  6. entry, err := client.Get(ctx, []byte(`hello`))
  7. if err != nil {
  8. log.Fatal(err)
  9. }
  10. fmt.Printf("Successfully retrieved entry: %v\n", entry)
  1. String key = "key1";
  2. byte[] value = new byte[]{1, 2, 3};
  3. try {
  4. immuClient.set(key, value);
  5. } catch (CorruptedDataException e) {
  6. // ...
  7. }
  8. try {
  9. value = immuClient.get(key);
  10. } catch (Exception e) {
  11. // ...
  12. }

Note that value is a primitive byte array. You can set the value of a String using:
"some string".getBytes(StandardCharsets.UTF_8)

Also, set method is overloaded to allow receiving the key parameter as a byte[] data type.

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectReading and inserting data - 图1 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  10. const setReq: Parameters.Set = { key: 'hello', value: 'world' }
  11. const setRes = await cl.set(setReq)
  12. console.log('success: set', setRes)
  13. const getReq: Parameters.Get = { key: 'hello' }
  14. const getRes = await cl.get(getReq)
  15. console.log('success: get', getRes)
  16. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectReading and inserting data - 图2 (opens new window)

If you’re using another development language, please read up on our immugwReading and inserting data - 图3 (opens new window) option.

Get at and since a transaction

You can retrieve a key on a specific transaction with VerifiedGetAt and since a specific transaction with VerifiedGetSince.

  1. ventry, err = client.VerifiedGetAt(ctx, []byte(`key`), meta.Id)
  2. if err != nil {
  3. log.Fatal(err)
  4. }
  5. fmt.Printf("Successfully retrieved entry at %v with value %s\n", ventry.Tx, ventry.Value)
  6. ventry, err = client.VerifiedGetSince(ctx, []byte(`key`), 4)
  7. if err != nil {
  8. log.Fatal(err)
  9. }
  10. fmt.Printf("Successfully retrieved entry at %v with value %s\n", ventry.Tx, ventry.Value)
  1. byte[] key = "key1".getBytes(StandardCharsets.UTF_8);
  2. byte[] val = new byte[]{1, 2, 3, 4, 5};
  3. TxMetadata txMd = null;
  4. try {
  5. txMd = immuClient.set(key, val);
  6. } catch (CorruptedDataException e) {
  7. // ...
  8. }
  9. // The standard (traditional) get options:
  10. KV kv = immuClient.getAt(key, txMd.id);
  11. kv = immuClient.getSince(key, txMd.id);
  12. // The verified get flavours:
  13. Entry vEntry = null;
  14. try {
  15. vEntry = immuClient.verifiedGetAt(key, vEntry.txId);
  16. } catch (VerificationException e) {
  17. // ...
  18. }
  19. try {
  20. vEntry = immuClient.verifiedGetSince(key, vEntry.txId);
  21. } catch (VerificationException e) {
  22. // ...
  23. }

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectReading and inserting data - 图4 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  10. const { id } = await cl.set({ key: 'key', value: 'value' })
  11. const verifiedGetAtReq: Parameters.VerifiedGetAt = {
  12. key: 'key',
  13. attx: id
  14. }
  15. const verifiedGetAtRes = await cl.verifiedGetAt(verifiedGetAtReq)
  16. console.log('success: verifiedGetAt', verifiedGetAtRes)
  17. for (let i = 0; i < 4; i++) {
  18. await cl.set({ key: 'key', value: `value-${i}` })
  19. }
  20. const verifiedGetSinceReq: Parameters.VerifiedGetSince = {
  21. key: 'key',
  22. sincetx: 2
  23. }
  24. const verifiedGetSinceRes = await cl.verifiedGetSince(verifiedGetSinceReq)
  25. console.log('success: verifiedGetSince', verifiedGetSinceRes)
  26. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectReading and inserting data - 图5 (opens new window)

If you’re using another development language, please read up on our immugwReading and inserting data - 图6 (opens new window) option.

Transaction by index

It’s possible to retrieve all the keys inside a specific transaction.

  1. setRequest := &schema.SetRequest{KVs: []*schema.KeyValue{
  2. {Key: []byte("key1"), Value: []byte("val1")},
  3. {Key: []byte("key2"), Value: []byte("val2")},
  4. }}
  5. meta, err := client.SetAll(ctx, setRequest)
  6. if err != nil {
  7. log.Fatal(err)
  8. }
  9. tx , err := client.TxByID(ctx, meta.Id)
  10. if err != nil {
  11. log.Fatal(err)
  12. }
  13. for _, entry := range tx.Entries {
  14. item, err := client.VerifiedGetAt(ctx, entry.Key, meta.Id)
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. fmt.Printf("retrieved key %s and val %s\n", item.Key, item.Value)
  19. }
  1. TxMetadata txMd = null;
  2. try {
  3. txMd = immuClient.verifiedSet(key, val);
  4. } catch (VerificationException e) {
  5. // ...
  6. }
  7. try {
  8. Tx tx = immuClient.txById(txMd.id);
  9. } catch (MaxWidthExceededException | NoSuchAlgorithmException e) {
  10. // ...
  11. }

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectReading and inserting data - 图7 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  10. const { id } = await cl.set({ key: 'key', value: 'value' })
  11. const txByIdReq: Parameters.TxById = { tx: id }
  12. const txByIdRes = await cl.txById(txByIdReq)
  13. console.log('success: txById', txByIdRes)
  14. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectReading and inserting data - 图8 (opens new window)

If you’re using another development language, please read up on our immugwReading and inserting data - 图9 (opens new window) option.

Verified transaction by index

It’s possible to retrieve all the keys inside a specific verified transaction.

  1. setRequest := &schema.SetRequest{KVs: []*schema.KeyValue{
  2. {Key: []byte("key1"), Value: []byte("val1")},
  3. {Key: []byte("key2"), Value: []byte("val2")},
  4. }}
  5. meta, err := client.SetAll(ctx, setRequest)
  6. if err != nil {
  7. log.Fatal(err)
  8. }
  9. tx , err := client.VerifiedTxByID(ctx, meta.Id)
  10. if err != nil {
  11. log.Fatal(err)
  12. }
  13. for _, entry := range tx.Entries {
  14. item, err := client.VerifiedGetAt(ctx, entry.Key, meta.Id)
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. fmt.Printf("retrieved key %s and val %s\n", item.Key, item.Value)
  19. }
  1. TxMetadata txMd = null;
  2. try {
  3. txMd = immuClient.verifiedSet(key, val);
  4. } catch (VerificationException e) {
  5. // ...
  6. }
  7. try {
  8. Tx tx = immuClient.verifiedTxById(txMd.id);
  9. } catch (VerificationException e) {
  10. // ...
  11. }

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on Python sdk github projectReading and inserting data - 图10 (opens new window)

  1. import ImmudbClient from 'immudb-node'
  2. import Parameters from 'immudb-node/types/parameters'
  3. const IMMUDB_HOST = '127.0.0.1'
  4. const IMMUDB_PORT = '3322'
  5. const IMMUDB_USER = 'immudb'
  6. const IMMUDB_PWD = 'immudb'
  7. const cl = new ImmudbClient({ host: IMMUDB_HOST, port: IMMUDB_PORT });
  8. (async () => {
  9. await cl.login({ user: IMMUDB_USER, password: IMMUDB_PWD })
  10. const { id } = await cl.set({ key: 'key', value: 'value' })
  11. const verifiedTxByIdReq: Parameters.VerifiedTxById = { tx: id }
  12. const verifiedTxByIdRes = await cl.verifiedTxByID(verifiedTxByIdReq)
  13. console.log('success: verifiedTxByID', verifiedTxByIdRes)
  14. })()

This feature is not yet supported or not documented. Do you want to make a feature request or help out? Open an issue on .Net sdk github projectReading and inserting data - 图11 (opens new window)

If you’re using another development language, please read up on our immugwReading and inserting data - 图12 (opens new window) option.