isNameExist method

  1. @override
Future<bool> isNameExist(
  1. String collectionId, {
  2. required String value,
  3. String name = 'name',
})
override

Implementation

@override
Future<bool> isNameExist(
  String collectionId, {
  required String value,
  String name = 'name',
}) async {
  await initialize();

  try {
    //String orderType = descending ? 'DESC' : 'ASC';

    List<String> queryList = [];
    queryList.add(Query.equal(name, value));

    final result = await database!.listDocuments(
      databaseId: myConfig!.serverConfig.dbConnInfo.appId,
      collectionId: collectionId,
      queries: queryList,
      // index 를 만들어줘야 함.
      //orderAttributes: [orderBy],
      //orderTypes: [orderType],
      //limit: limit,
      //offset: offset,
    );
    List<Map<String, dynamic>> retvalList = result.documents.map((doc) {
      //logger.finest(doc.data.toString());
      return doc.data;
    }).toList();

    if (retvalList.isEmpty) {
      return false;
    }
    return true;
  } on AppwriteException catch (e) {
    if (e.code == 404) {
      logger.finest(e.message!);
      return false;
    }
    logger.severe('database error !!!');
    if (e.message != null) {
      throw HycopException(message: e.message!, code: e.code);
    }
    throw HycopException(message: 'Appwrite error', code: e.code);
  }
}