add method
- T data
Adds a new document to the collection with the given data.
Parameters:
data: The data to add to the new document.
Returns:
A Future that resolves to the new DocumentReference.
Example:
var newDoc = await collection.add({'name': 'John'});
Implementation
Future<DocumentReference<T>> add(T data) async {
if (data is! Map && toConverter != null) {
data = toConverter(data);
}
dynamic document = null;
FusabaseAuth auth = FusabaseAuth.instanceFor(app: super._oracledb.app);
String? accessToken = await getAccessToken(auth);
if (checkOracledbApiVersion(oracledb.app.options, OracledbVersion["VERSION_1"] ?? 1)) {
document = setWholeData(this, {}, data, true);
document = parseTimestamp(document);
} else if (checkOracledbApiVersion(oracledb.app.options, OracledbVersion["VERSION_2"] ?? 2)) {
document = setWholeData(this, {}, data, true);
final embeddings = extractEmbeddingsMapForCreate(document);
if (embeddings.isNotEmpty) {
document.removeWhere((key, _) => embeddings.containsKey(key));
document[r'$embeddings'] = embeddings;
}
document = parseTimestamp(document);
}
Map<String, dynamic> result = await _helper.createdoc(
createClient(_oracledb.app), this, document, __logLevel, accessToken);
if (result['OID'] == null) {
throw Utils.oracledbErrorHandler(404, OracledbErrorMessages.docIdNotReturned, null);
}
DocumentReference<T> newDoc = DocumentReference<T>(
helper: QueryHelper(),
oracledb: _oracledb,
path: "${_path.join('/')}/${result['OID']}",
parent_: this);
newDoc.fromConverter = fromConverter;
newDoc.toConverter = toConverter;
return newDoc;
}