add method

  1. @override
Future<DualityViewDocReference<T>> add(
  1. T data
)
override

Adds a new document to the collection.

Parameters:

  • data: The data to add.

Returns: A Future that resolves to the new document reference.

Example:

var newDoc = await colRef.add({'name': 'New Item'});

Implementation

@override
/// Adds a new document to the collection.
///
/// Parameters:
/// - [data]: The data to add.
///
/// Returns:
/// A Future that resolves to the new document reference.
///
/// Example:
/// ```dart
/// var newDoc = await colRef.add({'name': 'New Item'});
/// ```
Future<DualityViewDocReference<T>> add(T data) async {
  FusabaseAuth auth = FusabaseAuth.instanceFor(app: super._oracledb.app);
  String? accessToken = await getAccessToken(auth);
  dynamic document = null;

  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, this.__logLevel, accessToken);

  if (result['OID'] == null) {
    throw Utils.oracledbErrorHandler(404, OracledbErrorMessages.docIdNotReturned, null);
  }
  return DualityViewDocReference<T>(
      helper: QueryHelper(),
      oracledb: _oracledb,
      path: "${_path.join('/')}/${result['OID']}",
      parent_: this);
}