fn add(&self, type_: &[u8], id: &[u8], value: &EncryptedValue, tags: &[Tag]) -> Result<(), WalletStorageError> {
        let pool = self.pool.clone();
        let conn = pool.get().unwrap();
        let query_qualifier = get_wallet_strategy_qualifier();
        let tx: transaction::Transaction = transaction::Transaction::new(&conn)?;
        let res = match query_qualifier {
            Some(_) => tx.prepare_cached("INSERT INTO items (type, name, value, key, wallet_id) VALUES ($1, $2, $3, $4, $5) RETURNING id")?
                .query(&[&type_.to_vec(), &id.to_vec(), &value.data, &value.key, &self.wallet_id]),
            None => tx.prepare_cached("INSERT INTO items (type, name, value, key) VALUES ($1, $2, $3, $4) RETURNING id")?
                .query(&[&type_.to_vec(), &id.to_vec(), &value.data, &value.key])
        };

        let item_id = match res {
            Ok(rows) => {
                let res = match rows.iter().next() {
                    Some(row) => Ok(row.get(0)),
                    None => Err(WalletStorageError::ItemNotFound)
                };
                let item_id: i64 = match res {
                    Err(WalletStorageError::ItemNotFound) => return Err(WalletStorageError::ItemNotFound),
                    Err(err) => return Err(WalletStorageError::from(err)),
                    Ok(id) => id
                };
                item_id
            }
            Err(err) => {
                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                    return Err(WalletStorageError::ItemAlreadyExists);
                } else {
                    return Err(WalletStorageError::from(err));
                }
            }
        };

        let item_id = item_id as i64;

        if !tags.is_empty() {
            let stmt_e = match query_qualifier {
                Some(_) => tx.prepare_cached("INSERT INTO tags_encrypted (item_id, name, value, wallet_id) VALUES ($1, $2, $3, $4)")?,
                None => tx.prepare_cached("INSERT INTO tags_encrypted (item_id, name, value) VALUES ($1, $2, $3)")?
            };
            let stmt_p = match query_qualifier {
                Some(_) => tx.prepare_cached("INSERT INTO tags_plaintext (item_id, name, value, wallet_id) VALUES ($1, $2, $3, $4)")?,
                None => tx.prepare_cached("INSERT INTO tags_plaintext (item_id, name, value) VALUES ($1, $2, $3)")?
            };

            for tag in tags {
                match tag {
                    &Tag::Encrypted(ref tag_name, ref tag_data) => {
                        let res = match query_qualifier {
                            Some(_) => stmt_e.execute(&[&item_id, tag_name, tag_data, &self.wallet_id]),
                            None => stmt_e.execute(&[&item_id, tag_name, tag_data])
                        };
                        match res {
                            Ok(_) => (),
                            Err(err) => {
                                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                                    return Err(WalletStorageError::ItemAlreadyExists);
                                } else {
                                    return Err(WalletStorageError::from(err));
                                }
                            }
                        }
                    }
                    &Tag::PlainText(ref tag_name, ref tag_data) => {
                        let res = match query_qualifier {
                            Some(_) => stmt_p.execute(&[&item_id, tag_name, tag_data, &self.wallet_id]),
                            None => stmt_p.execute(&[&item_id, tag_name, tag_data])
                        };
                        match res {
                            Ok(_) => (),
                            Err(err) => {
                                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                                    return Err(WalletStorageError::ItemAlreadyExists);
                                } else {
                                    return Err(WalletStorageError::from(err));
                                }
                            }
                        }
                    }
                };
            }
        }

        tx.commit()?;

        Ok(())
    }
///
/// inserts value and tags into storage.
/// Returns Result with () on success or
/// Result with WalletStorageError in case of failure.
///
///
/// # Arguments
///
///  * `type_` - type of the item in storage
///  * `id` - id of the item in storage
///  * `value` - value of the item in storage
///  * `value_key` - key used to encrypt the value
///  * `tags` - tags assigned to the value
///
/// # Returns
///
/// Result that can be either:
///
///  * `()`
///  * `WalletStorageError`
///
/// # Errors
///
/// Any of the following `WalletStorageError` class of errors can be throw by this method:
///
///  * `WalletStorageError::Closed` - Storage is closed
///  * `WalletStorageError::ItemAlreadyExists` - Item is already present in database
///  * `IOError("IO error during storage operation:...")` - Failed connection or SQL query
///
inserts value and tags into storage.
Returns Result with () on success or
Result with WalletStorageError in case of failure.
inserts value and tags into storage . Returns Result with () on success or Result with WalletStorageError in case of failure .
fn add(&self, type_: &[u8], id: &[u8], value: &EncryptedValue, tags: &[Tag]) -> Result<(), WalletStorageError> {
        let pool = self.pool.clone();
        let conn = pool.get().unwrap();
        let query_qualifier = get_wallet_strategy_qualifier();
        let tx: transaction::Transaction = transaction::Transaction::new(&conn)?;
        let res = match query_qualifier {
            Some(_) => tx.prepare_cached("INSERT INTO items (type, name, value, key, wallet_id) VALUES ($1, $2, $3, $4, $5) RETURNING id")?
                .query(&[&type_.to_vec(), &id.to_vec(), &value.data, &value.key, &self.wallet_id]),
            None => tx.prepare_cached("INSERT INTO items (type, name, value, key) VALUES ($1, $2, $3, $4) RETURNING id")?
                .query(&[&type_.to_vec(), &id.to_vec(), &value.data, &value.key])
        };
        let item_id = match res {
            Ok(rows) => {
                let res = match rows.iter().next() {
                    Some(row) => Ok(row.get(0)),
                    None => Err(WalletStorageError::ItemNotFound)
                };
                let item_id: i64 = match res {
                    Err(WalletStorageError::ItemNotFound) => return Err(WalletStorageError::ItemNotFound),
                    Err(err) => return Err(WalletStorageError::from(err)),
                    Ok(id) => id
                };
                item_id
            }
            Err(err) => {
                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                    return Err(WalletStorageError::ItemAlreadyExists);
                } else {
                    return Err(WalletStorageError::from(err));
                }
            }
        };
        let item_id = item_id as i64;
        if !tags.is_empty() {
            let stmt_e = match query_qualifier {
                Some(_) => tx.prepare_cached("INSERT INTO tags_encrypted (item_id, name, value, wallet_id) VALUES ($1, $2, $3, $4)")?,
                None => tx.prepare_cached("INSERT INTO tags_encrypted (item_id, name, value) VALUES ($1, $2, $3)")?
            };
            let stmt_p = match query_qualifier {
                Some(_) => tx.prepare_cached("INSERT INTO tags_plaintext (item_id, name, value, wallet_id) VALUES ($1, $2, $3, $4)")?,
                None => tx.prepare_cached("INSERT INTO tags_plaintext (item_id, name, value) VALUES ($1, $2, $3)")?
            };
            for tag in tags {
                match tag {
                    &Tag::Encrypted(ref tag_name, ref tag_data) => {
                        let res = match query_qualifier {
                            Some(_) => stmt_e.execute(&[&item_id, tag_name, tag_data, &self.wallet_id]),
                            None => stmt_e.execute(&[&item_id, tag_name, tag_data])
                        };
                        match res {
                            Ok(_) => (),
                            Err(err) => {
                                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                                    return Err(WalletStorageError::ItemAlreadyExists);
                                } else {
                                    return Err(WalletStorageError::from(err));
                                }
                            }
                        }
                    }
                    &Tag::PlainText(ref tag_name, ref tag_data) => {
                        let res = match query_qualifier {
                            Some(_) => stmt_p.execute(&[&item_id, tag_name, tag_data, &self.wallet_id]),
                            None => stmt_p.execute(&[&item_id, tag_name, tag_data])
                        };
                        match res {
                            Ok(_) => (),
                            Err(err) => {
                                if err.code() == Some(&postgres::error::UNIQUE_VIOLATION) ||
                                    err.code() == Some(&postgres::error::INTEGRITY_CONSTRAINT_VIOLATION) {
                                    return Err(WalletStorageError::ItemAlreadyExists);
                                } else {
                                    return Err(WalletStorageError::from(err));
                                }
                            }
                        }
                    }
                };
            }
        }
        tx.commit()?;
        Ok(())
    }
fn add ( & self , type_ : & [ u8 ] , id : & [ u8 ] , value : & EncryptedValue , tags : & [ Tag ] ) -> Result < ( ) , WalletStorageError > { let pool = self . pool . clone ( ) ; let conn = pool . get ( ) . unwrap ( ) ; let query_qualifier = get_wallet_strategy_qualifier ( ) ; let tx : transaction :: Transaction = transaction :: Transaction :: new ( & conn ) ? ; let res = match query_qualifier { Some ( _ ) => tx . prepare_cached ( " " ) ? . query ( & [ & type_ . to_vec ( ) , & id . to_vec ( ) , & value . data , & value . key , & self . wallet_id ] ) , None => tx . prepare_cached ( " " ) ? . query ( & [ & type_ . to_vec ( ) , & id . to_vec ( ) , & value . data , & value . key ] ) } ; let item_id = match res { Ok ( rows ) => { let res = match rows . iter ( ) . next ( ) { Some ( row ) => Ok ( row . get ( 0 ) ) , None => Err ( WalletStorageError :: ItemNotFound ) } ; let item_id : i64 = match res { Err ( WalletStorageError :: ItemNotFound ) => return Err ( WalletStorageError :: ItemNotFound ) , Err ( err ) => return Err ( WalletStorageError :: from ( err ) ) , Ok ( id ) => id } ; item_id } Err ( err ) => { if err . code ( ) == Some ( & postgres :: error :: UNIQUE_VIOLATION ) || err . code ( ) == Some ( & postgres :: error :: INTEGRITY_CONSTRAINT_VIOLATION ) { return Err ( WalletStorageError :: ItemAlreadyExists ) ; } else { return Err ( WalletStorageError :: from ( err ) ) ; } } } ; let item_id = item_id as i64 ; if ! tags . is_empty ( ) { let stmt_e = match query_qualifier { Some ( _ ) => tx . prepare_cached ( " " ) ? , None => tx . prepare_cached ( " " ) ? } ; let stmt_p = match query_qualifier { Some ( _ ) => tx . prepare_cached ( " " ) ? , None => tx . prepare_cached ( " " ) ? } ; for tag in tags { match tag { & Tag :: Encrypted ( ref tag_name , ref tag_data ) => { let res = match query_qualifier { Some ( _ ) => stmt_e . execute ( & [ & item_id , tag_name , tag_data , & self . wallet_id ] ) , None => stmt_e . execute ( & [ & item_id , tag_name , tag_data ] ) } ; match res { Ok ( _ ) => ( ) , Err ( err ) => { if err . code ( ) == Some ( & postgres :: error :: UNIQUE_VIOLATION ) || err . code ( ) == Some ( & postgres :: error :: INTEGRITY_CONSTRAINT_VIOLATION ) { return Err ( WalletStorageError :: ItemAlreadyExists ) ; } else { return Err ( WalletStorageError :: from ( err ) ) ; } } } } & Tag :: PlainText ( ref tag_name , ref tag_data ) => { let res = match query_qualifier { Some ( _ ) => stmt_p . execute ( & [ & item_id , tag_name , tag_data , & self . wallet_id ] ) , None => stmt_p . execute ( & [ & item_id , tag_name , tag_data ] ) } ; match res { Ok ( _ ) => ( ) , Err ( err ) => { if err . code ( ) == Some ( & postgres :: error :: UNIQUE_VIOLATION ) || err . code ( ) == Some ( & postgres :: error :: INTEGRITY_CONSTRAINT_VIOLATION ) { return Err ( WalletStorageError :: ItemAlreadyExists ) ; } else { return Err ( WalletStorageError :: from ( err ) ) ; } } } } } ; } } tx . commit ( ) ? ; Ok ( ( ) ) }
inserts value and tags into storage.
inserts value and tags into storage .
&self
type_
&[u8]
id
&[u8]
value
&EncryptedValue
tags
&[Tag]
Result that can be either.

`()`
`WalletStorageError`
Result that can be either . ` () ` ` WalletStorageError `
&self
type_
&[u8]
id
&[u8]
value
&EncryptedValue
tags
&[Tag]
errors
Any of the following `WalletStorageError` class of errors can be throw by this method.

`WalletStorageError::Closed` - Storage is closed
`WalletStorageError::ItemAlreadyExists` - Item is already present in database
`IOError("IO error during storage operation:...")` - Failed connection or SQL query
Any of the following ` WalletStorageError ` class of errors can be throw by this method . ` WalletStorageError :: Closed ` - Storage is closed ` WalletStorageError :: ItemAlreadyExists ` - Item is already present in database ` IOError ( " IO error during storage operation : ... " ) ` - Failed connection or SQL query