2020-03-27 02:20:07 +13:00
|
|
|
import 'dart:html';
|
|
|
|
|
2020-01-31 05:18:59 +13:00
|
|
|
import "package:appwrite/service.dart";
|
|
|
|
import "package:appwrite/client.dart";
|
|
|
|
import 'package:dio/dio.dart';
|
2020-03-27 02:20:07 +13:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
|
|
|
import '../enums.dart';
|
2020-01-31 05:18:59 +13:00
|
|
|
|
|
|
|
class Database extends Service {
|
|
|
|
|
|
|
|
Database(Client client): super(client);
|
|
|
|
|
|
|
|
/// Get a list of all the user documents. You can use the query params to
|
|
|
|
/// filter your results. On admin mode, this endpoint will return a list of all
|
|
|
|
/// of the project documents. [Learn more about different API
|
|
|
|
/// modes](/docs/admin).
|
2020-03-27 02:20:07 +13:00
|
|
|
Future<Response> listDocuments({@required String collectionId, List filters = const [], int offset = null, int limit = 50, String orderField = '\$id', String orderType = 'ASC', String orderCast = 'string', String search = null, int first = null, int last = null}) async {
|
2020-01-31 05:18:59 +13:00
|
|
|
String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
'filters': filters,
|
|
|
|
'offset': offset,
|
|
|
|
'limit': limit,
|
|
|
|
'order-field': orderField,
|
|
|
|
'order-type': orderType,
|
|
|
|
'order-cast': orderCast,
|
|
|
|
'search': search,
|
|
|
|
'first': first,
|
|
|
|
'last': last,
|
|
|
|
};
|
|
|
|
|
2020-03-27 02:20:07 +13:00
|
|
|
return await this.client.call(HttpMethod.get, path: path, params: params);
|
2020-01-31 05:18:59 +13:00
|
|
|
}
|
|
|
|
/// Create a new Document.
|
2020-03-27 02:20:07 +13:00
|
|
|
Future<Response> createDocument({@required String collectionId, @required dynamic data, @required List read, @required List write, String parentDocument = null, String parentProperty = null, String parentPropertyType = 'assign'}) async {
|
2020-01-31 05:18:59 +13:00
|
|
|
String path = '/database/collections/{collectionId}/documents'.replaceAll(RegExp('{collectionId}'), collectionId);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
'data': data,
|
|
|
|
'read': read,
|
|
|
|
'write': write,
|
|
|
|
'parentDocument': parentDocument,
|
|
|
|
'parentProperty': parentProperty,
|
|
|
|
'parentPropertyType': parentPropertyType,
|
|
|
|
};
|
|
|
|
|
2020-03-27 02:20:07 +13:00
|
|
|
return await this.client.call(HttpMethod.post, path: path, params: params);
|
2020-01-31 05:18:59 +13:00
|
|
|
}
|
|
|
|
/// Get document by its unique ID. This endpoint response returns a JSON object
|
|
|
|
/// with the document data.
|
2020-03-27 02:20:07 +13:00
|
|
|
Future<Response> getDocument({@required String collectionId, @required String documentId}) async {
|
2020-01-31 05:18:59 +13:00
|
|
|
String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
};
|
|
|
|
|
2020-03-27 02:20:07 +13:00
|
|
|
return await this.client.call(HttpMethod.get, path: path, params: params);
|
2020-01-31 05:18:59 +13:00
|
|
|
}
|
2020-03-27 02:20:07 +13:00
|
|
|
Future<Response> updateDocument({@required String collectionId, @required String documentId, @required dynamic data, @required List read, @required List write}) async {
|
2020-01-31 05:18:59 +13:00
|
|
|
String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
'data': data,
|
|
|
|
'read': read,
|
|
|
|
'write': write,
|
|
|
|
};
|
|
|
|
|
2020-03-27 02:20:07 +13:00
|
|
|
return await this.client.call(HttpMethod.patch, path: path, params: params);
|
2020-01-31 05:18:59 +13:00
|
|
|
}
|
|
|
|
/// Delete document by its unique ID. This endpoint deletes only the parent
|
|
|
|
/// documents, his attributes and relations to other documents. Child documents
|
|
|
|
/// **will not** be deleted.
|
2020-03-27 02:20:07 +13:00
|
|
|
Future<Response> deleteDocument({@required String collectionId, @required String documentId}) async {
|
2020-01-31 05:18:59 +13:00
|
|
|
String path = '/database/collections/{collectionId}/documents/{documentId}'.replaceAll(RegExp('{collectionId}'), collectionId).replaceAll(RegExp('{documentId}'), documentId);
|
|
|
|
|
|
|
|
Map<String, dynamic> params = {
|
|
|
|
};
|
|
|
|
|
2020-03-27 02:20:07 +13:00
|
|
|
return await this.client.call(HttpMethod.delete, path: path, params: params);
|
2020-01-31 05:18:59 +13:00
|
|
|
}
|
|
|
|
}
|