create method

Future<Map<String, dynamic>> create(
  1. {bool waitForSync,
  2. int journalSize,
  3. bool isVolatile,
  4. bool isSystem,
  5. int numberOfShards,
  6. List<String> shardKeys,
  7. String distributeShardsLike,
  8. String shardingStrategy,
  9. String smartJoinAttribute,
  10. int replicationFactor,
  11. int minReplicationFactor,
  12. bool waitForSyncReplication,
  13. bool enforceReplicationFactor,
  14. KeyGeneratorType keyType,
  15. bool keyAllowUserKeys,
  16. int keyIncrement,
  17. int keyOffset}
)

Implementation

Future<Map<String, dynamic>> create({
  bool waitForSync,
  int journalSize,
  bool isVolatile,
  bool isSystem,
  int numberOfShards,
  List<String> shardKeys,
  String distributeShardsLike,
  String shardingStrategy,
  String smartJoinAttribute,
  int replicationFactor,
  int minReplicationFactor,
  bool waitForSyncReplication,
  bool enforceReplicationFactor,
  KeyGeneratorType keyType,
  bool keyAllowUserKeys,
  int keyIncrement,
  int keyOffset,
}) async {
  final body = {
    'name': name,
    'type': type,
    if (waitForSync != null) 'waitForSync': waitForSync,
    if (journalSize != null) 'journalSize': journalSize,
    if (isVolatile != null) 'isVolatile': isVolatile,
    if (isSystem != null) 'isSystem': isSystem,
    'keyOptions': {
      if (keyType != null) 'type': keyType,
      if (keyAllowUserKeys != null) 'allowUserKeys': keyAllowUserKeys,
      if (keyIncrement != null) 'increment': keyIncrement,
      if (keyOffset != null) 'offset': keyOffset,
    },
    if (numberOfShards != null) 'numberOfShards': numberOfShards,
    if (shardKeys != null) 'shardKeys': shardKeys,
    if (distributeShardsLike != null)
      'distributeShardsLike': distributeShardsLike,
    if (shardingStrategy != null) 'shardingStrategy': shardingStrategy,
    if (smartJoinAttribute != null) 'smartJoinAttribute': smartJoinAttribute,
    if (replicationFactor != null) 'replicationFactor': replicationFactor,
    if (minReplicationFactor != null)
      'minReplicationFactor': minReplicationFactor,
  };

  final qs = <String, String>{};
  if (waitForSyncReplication != null) {
    qs['waitForSyncReplication'] = waitForSyncReplication ? '1' : '0';
  }
  if (enforceReplicationFactor != null) {
    qs['enforceReplicationFactor'] = enforceReplicationFactor ? '1' : '0';
  }

  final resp = await _connection.request(
    method: 'POST',
    path: '/_api/collection',
    body: body,
    queries: qs,
  );

  return resp.body;
}