Class: Appwrite::Database

Inherits:
Service
  • Object
show all
Defined in:
lib/appwrite/services/database.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#create_boolean_attribute(collection_id:, key:, required:, default: nil, array: nil) ⇒ AttributeBoolean

Create a boolean attribute.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • default (boolean) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeBoolean)


242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/appwrite/services/database.rb', line 242

def create_boolean_attribute(collection_id:, key:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/boolean'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeBoolean
    )
end

#create_collection(collection_id:, name:, permission:, read:, write:) ⇒ Collection

Create a new Collection.

Parameters:

  • collection_id (string)

    Unique Id. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • name (string)

    Collection name. Max length: 128 chars.

  • permission (string)

    Permissions type model to use for reading documents in this collection. You can use collection-level permission set once on the collection using the ‘read` and `write` params, or you can set document-level permission where each document read and write params will decide who has access to read and write to each document individually. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • read (array)

    An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • write (array)

    An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

Returns:

  • (Collection)


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/appwrite/services/database.rb', line 53

def create_collection(collection_id:, name:, permission:, read:, write:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if permission.nil?
        raise Appwrite::Exception.new('Missing required parameter: "permission"')
    end

    if read.nil?
        raise Appwrite::Exception.new('Missing required parameter: "read"')
    end

    if write.nil?
        raise Appwrite::Exception.new('Missing required parameter: "write"')
    end

    path = '/database/collections'

    params = {
        collectionId: collection_id,
        name: name,
        permission: permission,
        read: read,
        write: write,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Collection
    )
end

#create_document(collection_id:, document_id:, data:, read: nil, write: nil) ⇒ Document

Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](/docs/server/database#databaseCreateCollection) API or directly from your database console.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection). Make sure to define attributes before creating documents.

  • document_id (string)

    Document ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • data (object)

    Document data as JSON object.

  • read (array) (defaults to: nil)

    An array of strings with read permissions. By default only the current user is granted with read permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • write (array) (defaults to: nil)

    An array of strings with write permissions. By default only the current user is granted with write permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

Returns:

  • (Document)


747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
# File 'lib/appwrite/services/database.rb', line 747

def create_document(collection_id:, document_id:, data:, read: nil, write: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if document_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "documentId"')
    end

    if data.nil?
        raise Appwrite::Exception.new('Missing required parameter: "data"')
    end

    path = '/database/collections/{collectionId}/documents'
        .gsub('{collectionId}', collection_id)

    params = {
        documentId: document_id,
        data: data,
        read: read,
        write: write,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Document
    )
end

#create_email_attribute(collection_id:, key:, required:, default: nil, array: nil) ⇒ AttributeEmail

Create an email attribute.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • default (string) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeEmail)


288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/appwrite/services/database.rb', line 288

def create_email_attribute(collection_id:, key:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/email'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeEmail
    )
end

#create_enum_attribute(collection_id:, key:, elements:, required:, default: nil, array: nil) ⇒ AttributeEnum

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • elements (array)

    Array of elements in enumerated type. Uses length of longest element to determine size.

  • required (boolean)

    Is attribute required?

  • default (string) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeEnum)


334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'lib/appwrite/services/database.rb', line 334

def create_enum_attribute(collection_id:, key:, elements:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if elements.nil?
        raise Appwrite::Exception.new('Missing required parameter: "elements"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/enum'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        elements: elements,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeEnum
    )
end

#create_float_attribute(collection_id:, key:, required:, min: nil, max: nil, default: nil, array: nil) ⇒ AttributeFloat

Create a float attribute. Optionally, minimum and maximum values can be provided.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • min (number) (defaults to: nil)

    Minimum value to enforce on new documents

  • max (number) (defaults to: nil)

    Maximum value to enforce on new documents

  • default (number) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeFloat)


388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/appwrite/services/database.rb', line 388

def create_float_attribute(collection_id:, key:, required:, min: nil, max: nil, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/float'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        min: min,
        max: max,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeFloat
    )
end

#create_index(collection_id:, key:, type:, attributes:, orders: nil) ⇒ Index

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Index Key.

  • type (string)

    Index type.

  • attributes (array)

    Array of attributes to index.

  • orders (array) (defaults to: nil)

    Array of index orders.

Returns:

  • (Index)


939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# File 'lib/appwrite/services/database.rb', line 939

def create_index(collection_id:, key:, type:, attributes:, orders: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if type.nil?
        raise Appwrite::Exception.new('Missing required parameter: "type"')
    end

    if attributes.nil?
        raise Appwrite::Exception.new('Missing required parameter: "attributes"')
    end

    path = '/database/collections/{collectionId}/indexes'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        type: type,
        attributes: attributes,
        orders: orders,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Index
    )
end

#create_integer_attribute(collection_id:, key:, required:, min: nil, max: nil, default: nil, array: nil) ⇒ AttributeInteger

Create an integer attribute. Optionally, minimum and maximum values can be provided.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • min (number) (defaults to: nil)

    Minimum value to enforce on new documents

  • max (number) (defaults to: nil)

    Maximum value to enforce on new documents

  • default (number) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeInteger)


439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/appwrite/services/database.rb', line 439

def create_integer_attribute(collection_id:, key:, required:, min: nil, max: nil, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/integer'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        min: min,
        max: max,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeInteger
    )
end

#create_ip_attribute(collection_id:, key:, required:, default: nil, array: nil) ⇒ AttributeIp

Create IP address attribute.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • default (string) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeIp)


487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/appwrite/services/database.rb', line 487

def create_ip_attribute(collection_id:, key:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/ip'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeIp
    )
end

#create_string_attribute(collection_id:, key:, size:, required:, default: nil, array: nil) ⇒ AttributeString

Create a string attribute.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • size (number)

    Attribute size for text attributes, in number of characters.

  • required (boolean)

    Is attribute required?

  • default (string) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeString)


534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/appwrite/services/database.rb', line 534

def create_string_attribute(collection_id:, key:, size:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if size.nil?
        raise Appwrite::Exception.new('Missing required parameter: "size"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/string'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        size: size,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeString
    )
end

#create_url_attribute(collection_id:, key:, required:, default: nil, array: nil) ⇒ AttributeUrl

Create a URL attribute.

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • key (string)

    Attribute Key.

  • required (boolean)

    Is attribute required?

  • default (string) (defaults to: nil)

    Default value for attribute when not provided. Cannot be set when attribute is required.

  • array (boolean) (defaults to: nil)

    Is attribute an array?

Returns:

  • (AttributeUrl)


585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/appwrite/services/database.rb', line 585

def create_url_attribute(collection_id:, key:, required:, default: nil, array: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    if required.nil?
        raise Appwrite::Exception.new('Missing required parameter: "required"')
    end

    path = '/database/collections/{collectionId}/attributes/url'
        .gsub('{collectionId}', collection_id)

    params = {
        key: key,
        required: required,
        default: default,
        array: array,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeUrl
    )
end

#delete_attribute(collection_id:, key:) ⇒ Object

Returns [].

Parameters:

Returns:



661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/appwrite/services/database.rb', line 661

def delete_attribute(collection_id:, key:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    path = '/database/collections/{collectionId}/attributes/{key}'
        .gsub('{collectionId}', collection_id)
        .gsub('{key}', key)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_collection(collection_id:) ⇒ Object

Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.

Parameters:

  • collection_id (string)

    Collection ID.

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/appwrite/services/database.rb', line 180

def delete_collection(collection_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    path = '/database/collections/{collectionId}'
        .gsub('{collectionId}', collection_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_document(collection_id:, document_id:) ⇒ Object

Delete a document by its unique ID. This endpoint deletes only the parent documents, its attributes and relations to other documents. Child documents **will not** be deleted.

Parameters:

Returns:



873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'lib/appwrite/services/database.rb', line 873

def delete_document(collection_id:, document_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if document_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "documentId"')
    end

    path = '/database/collections/{collectionId}/documents/{documentId}'
        .gsub('{collectionId}', collection_id)
        .gsub('{documentId}', document_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_index(collection_id:, key:) ⇒ Object

Returns [].

Parameters:

Returns:



1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/appwrite/services/database.rb', line 1020

def delete_index(collection_id:, key:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    path = '/database/collections/{collectionId}/indexes/{key}'
        .gsub('{collectionId}', collection_id)
        .gsub('{key}', key)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_attribute(collection_id:, key:) ⇒ Object

Returns [].

Parameters:

Returns:



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/appwrite/services/database.rb', line 627

def get_attribute(collection_id:, key:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    path = '/database/collections/{collectionId}/attributes/{key}'
        .gsub('{collectionId}', collection_id)
        .gsub('{key}', key)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
    )
end

#get_collection(collection_id:) ⇒ Collection

Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.

Parameters:

  • collection_id (string)

    Collection ID.

Returns:

  • (Collection)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/appwrite/services/database.rb', line 103

def get_collection(collection_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    path = '/database/collections/{collectionId}'
        .gsub('{collectionId}', collection_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Collection
    )
end

#get_document(collection_id:, document_id:) ⇒ Document

Get a document by its unique ID. This endpoint response returns a JSON object with the document data.

Parameters:

Returns:

  • (Document)


790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/appwrite/services/database.rb', line 790

def get_document(collection_id:, document_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if document_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "documentId"')
    end

    path = '/database/collections/{collectionId}/documents/{documentId}'
        .gsub('{collectionId}', collection_id)
        .gsub('{documentId}', document_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Document
    )
end

#get_index(collection_id:, key:) ⇒ Index

Parameters:

Returns:

  • (Index)


985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
# File 'lib/appwrite/services/database.rb', line 985

def get_index(collection_id:, key:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if key.nil?
        raise Appwrite::Exception.new('Missing required parameter: "key"')
    end

    path = '/database/collections/{collectionId}/indexes/{key}'
        .gsub('{collectionId}', collection_id)
        .gsub('{key}', key)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Index
    )
end

#list_attributes(collection_id:) ⇒ AttributeList

Parameters:

Returns:

  • (AttributeList)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/appwrite/services/database.rb', line 208

def list_attributes(collection_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    path = '/database/collections/{collectionId}/attributes'
        .gsub('{collectionId}', collection_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::AttributeList
    )
end

#list_collections(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ CollectionList

Get a list of all the user collections. You can use the query params to filter your results. On admin mode, this endpoint will return a list of all of the project’s collections. [Learn more about different API modes](/docs/admin).

Parameters:

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • limit (number) (defaults to: nil)

    Maximum number of collection to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this param to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the collection used as the starting point for the query, excluding the collection itself. Should be used for efficient pagination when working with large sets of data.

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (CollectionList)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/appwrite/services/database.rb', line 19

def list_collections(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    path = '/database/collections'

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::CollectionList
    )
end

#list_documents(collection_id:, queries: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_attributes: nil, order_types: nil) ⇒ DocumentList

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’s documents. [Learn more about different API modes](/docs/admin).

Parameters:

  • collection_id (string)

    Collection ID. You can create a new collection using the Database service [server integration](appwrite.io/docs/server/database#createCollection).

  • queries (array) (defaults to: nil)

    Array of query strings.

  • limit (number) (defaults to: nil)

    Maximum number of documents to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the document used as the starting point for the query, excluding the document itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor.

  • order_attributes (array) (defaults to: nil)

    Array of attributes used to sort results.

  • order_types (array) (defaults to: nil)

    Array of order directions for sorting attribtues. Possible values are DESC for descending order, or ASC for ascending order.

Returns:

  • (DocumentList)


704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/appwrite/services/database.rb', line 704

def list_documents(collection_id:, queries: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_attributes: nil, order_types: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    path = '/database/collections/{collectionId}/documents'
        .gsub('{collectionId}', collection_id)

    params = {
        queries: queries,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderAttributes: order_attributes,
        orderTypes: order_types,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::DocumentList
    )
end

#list_indexes(collection_id:) ⇒ IndexList

Parameters:

Returns:

  • (IndexList)


906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'lib/appwrite/services/database.rb', line 906

def list_indexes(collection_id:)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    path = '/database/collections/{collectionId}/indexes'
        .gsub('{collectionId}', collection_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::IndexList
    )
end

#update_collection(collection_id:, name:, permission:, read: nil, write: nil, enabled: nil) ⇒ Collection

Update a collection by its unique ID.

Parameters:

  • collection_id (string)

    Collection ID.

  • name (string)

    Collection name. Max length: 128 chars.

  • permission (string)

    Permissions type model to use for reading documents in this collection. You can use collection-level permission set once on the collection using the ‘read` and `write` params, or you can set document-level permission where each document read and write params will decide who has access to read and write to each document individually. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • read (array) (defaults to: nil)

    An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • write (array) (defaults to: nil)

    An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • enabled (boolean) (defaults to: nil)

    Is collection enabled?

Returns:

  • (Collection)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/appwrite/services/database.rb', line 137

def update_collection(collection_id:, name:, permission:, read: nil, write: nil, enabled: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if permission.nil?
        raise Appwrite::Exception.new('Missing required parameter: "permission"')
    end

    path = '/database/collections/{collectionId}'
        .gsub('{collectionId}', collection_id)

    params = {
        name: name,
        permission: permission,
        read: read,
        write: write,
        enabled: enabled,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Collection
    )
end

#update_document(collection_id:, document_id:, data:, read: nil, write: nil) ⇒ Document

Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.

Parameters:

  • collection_id (string)

    Collection ID.

  • document_id (string)

    Document ID.

  • data (object)

    Document data as JSON object.

  • read (array) (defaults to: nil)

    An array of strings with read permissions. By default inherits the existing read permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

  • write (array) (defaults to: nil)

    An array of strings with write permissions. By default inherits the existing write permissions. [learn more about permissions](appwrite.io/docs/permissions) and get a full list of available permissions.

Returns:

  • (Document)


829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
# File 'lib/appwrite/services/database.rb', line 829

def update_document(collection_id:, document_id:, data:, read: nil, write: nil)
    if collection_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "collectionId"')
    end

    if document_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "documentId"')
    end

    if data.nil?
        raise Appwrite::Exception.new('Missing required parameter: "data"')
    end

    path = '/database/collections/{collectionId}/documents/{documentId}'
        .gsub('{collectionId}', collection_id)
        .gsub('{documentId}', document_id)

    params = {
        data: data,
        read: read,
        write: write,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Document
    )
end