addValue method
Implementation
Future<void> addValue(String path, NodeValue value) async {
checkPath(path);
await get(path);
if (await getValue(path, value.key) != null) {
throw StorageException('Value "${value.key}" already exists');
}
String sqlStatement =
('INSERT INTO node_value (path, key, value, type, locale, '
'last_modified) VALUES (?,?,?,?,?,?)');
try {
_requestResult(sqlStatement, [
path,
value.key,
value.value,
value.type,
NodeValueImpl.defaultLocale.toLanguageTag(),
value.lastModified
]);
} on StorageException catch (e) {
throw StorageException('Could not create value "${value.key}"', null, e);
}
String sqlStatementTrl =
('INSERT INTO translation (path, key, identifier, locale, translation)'
' VALUES (?,?,?,?,?)');
Map<Locale, String> valueMap = value.allValueTranslations;
for (MapEntry<Locale, String> entry in valueMap.entries) {
try {
_requestResult(sqlStatementTrl,
[path, value.key, 'VALUE', entry.key.toLanguageTag(), entry.value]);
} on StorageException catch (e) {
throw StorageException(
'Could not create translation "' +
entry.key.toLanguageTag() +
'" for value "' +
value.key +
'"',
null,
e);
}
}
Map<Locale, String> descriptionMap = value.allDescriptionTranslations;
for (MapEntry<Locale, String> entry in descriptionMap.entries) {
try {
_requestResult(sqlStatementTrl, [
path,
value.key,
'DESCRIPTION',
entry.key.toLanguageTag(),
entry.value
]);
} on StorageException catch (e) {
throw StorageException(
'Could not create translation "' +
entry.key.toLanguageTag() +
'" for description in value "' +
value.key +
'"',
null,
e);
}
}
}