{{ message }}
Repository navigation
Expand file tree
/
Copy pathdatabases.py
More file actions
5202 lines (4735 loc) · 207 KB
/
Copy pathdatabases.py
File metadata and controls
5202 lines (4735 loc) · 207 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
277
278
279
280
281
282
283
284
285
286
287
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
323
324
325
326
327
328
329
330
331
332
333
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
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
476
477
478
479
480
481
482
483
484
485
486
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
522
523
524
525
526
527
528
529
530
531
532
533
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
574
575
576
577
578
579
580
581
582
583
584
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
620
621
622
623
624
625
626
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
654
655
656
657
658
659
660
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
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
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
734
735
736
737
738
739
740
741
742
743
744
745
746
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
782
783
784
785
786
787
788
789
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
818
819
820
821
822
823
824
825
826
827
828
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
864
865
866
867
868
869
870
871
872
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
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
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
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from ..service import Service
from urllib.parse import quote
from typing import Any, Dict, List, Optional, Union, Type, TypeVar
from ..exception import AppwriteException
from appwrite.utils.deprecated import deprecated
from ..models.database_list import DatabaseList
from ..models.database import Database
from ..models.transaction_list import TransactionList
from ..models.transaction import Transaction
from ..models.collection_list import CollectionList
from ..models.collection import Collection
from ..models.attribute_list import AttributeList
from ..models.attribute_bigint import AttributeBigint
from ..models.attribute_boolean import AttributeBoolean
from ..models.attribute_datetime import AttributeDatetime
from ..models.attribute_email import AttributeEmail
from ..models.attribute_enum import AttributeEnum
from ..models.attribute_float import AttributeFloat
from ..models.attribute_integer import AttributeInteger
from ..models.attribute_ip import AttributeIp
from ..models.attribute_line import AttributeLine
from ..models.attribute_longtext import AttributeLongtext
from ..models.attribute_mediumtext import AttributeMediumtext
from ..models.attribute_point import AttributePoint
from ..models.attribute_polygon import AttributePolygon
from ..enums.relationship_type import RelationshipType
from ..enums.relation_mutate import RelationMutate
from ..models.attribute_relationship import AttributeRelationship
from ..models.attribute_string import AttributeString
from ..models.attribute_text import AttributeText
from ..models.attribute_url import AttributeUrl
from ..models.attribute_varchar import AttributeVarchar
from ..models.document_list import DocumentList
from ..models.document import Document
from ..models.index_list import IndexList
from ..enums.databases_index_type import DatabasesIndexType
from ..enums.order_by import OrderBy
from ..models.index import Index
T = TypeVar('T')
class Databases(Service):
def __init__(self, client) -> None:
super(Databases, self).__init__(client)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list` instead.")
def list(
self,
queries: Optional[List[str]] = None,
search: Optional[str] = None,
total: Optional[bool] = None,
) -> DatabaseList:
"""
Get a list of all databases from the current Appwrite project. You can use the search parameter to filter your results.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.list` instead.
Parameters
----------
queries : Optional[List[str]]
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name
search : Optional[str]
Search term to filter your list results. Max length: 256 chars.
total : Optional[bool]
When set to false, the total count returned will be 0 and will not be calculated.
Returns
-------
DatabaseList
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases'
api_params = {}
if queries is not None:
api_params['queries'] = self._normalize_value(queries)
if search is not None:
api_params['search'] = self._normalize_value(search)
if total is not None:
api_params['total'] = self._normalize_value(total)
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=DatabaseList)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create` instead.")
def create(
self,
database_id: str,
name: str,
enabled: Optional[bool] = None,
description: Optional[str] = None,
) -> Database:
"""
Create a new Database.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.create` instead.
Parameters
----------
database_id : str
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 : str
Database name. Max length: 128 chars.
enabled : Optional[bool]
Is the database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.
description : Optional[str]
Optional description for the database.
Returns
-------
Database
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases'
api_params = {}
if database_id is None:
raise AppwriteException('Missing required parameter: "database_id"')
if name is None:
raise AppwriteException('Missing required parameter: "name"')
api_params['databaseId'] = self._normalize_value(database_id)
api_params['name'] = self._normalize_value(name)
if enabled is not None:
api_params['enabled'] = self._normalize_value(enabled)
if description is not None:
api_params['description'] = self._normalize_value(description)
response = self.client.call(
'post',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Database)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_transactions` instead.")
def list_transactions(
self,
queries: Optional[List[str]] = None,
total: Optional[bool] = None,
) -> TransactionList:
"""
List transactions across all databases.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.list_transactions` instead.
Parameters
----------
queries : Optional[List[str]]
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries).
total : Optional[bool]
When set to false, the total count returned will be 0 and will not be calculated.
Returns
-------
TransactionList
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions'
api_params = {}
if queries is not None:
api_params['queries'] = self._normalize_value(queries)
if total is not None:
api_params['total'] = self._normalize_value(total)
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=TransactionList)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_transaction` instead.")
def create_transaction(
self,
ttl: Optional[float] = None,
) -> Transaction:
"""
Create a new transaction.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.create_transaction` instead.
Parameters
----------
ttl : Optional[float]
Seconds before the transaction expires.
Returns
-------
Transaction
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions'
api_params = {}
if ttl is not None:
api_params['ttl'] = self._normalize_value(ttl)
response = self.client.call(
'post',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Transaction)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_transaction` instead.")
def get_transaction(
self,
transaction_id: str,
) -> Transaction:
"""
Get a transaction by its unique ID.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.get_transaction` instead.
Parameters
----------
transaction_id : str
Transaction ID.
Returns
-------
Transaction
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions/{transactionId}'
api_params = {}
if transaction_id is None or transaction_id == '':
raise AppwriteException('Missing required parameter: "transaction_id"')
api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id)))
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Transaction)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_transaction` instead.")
def update_transaction(
self,
transaction_id: str,
commit: Optional[bool] = None,
rollback: Optional[bool] = None,
) -> Transaction:
"""
Update a transaction, to either commit or roll back its operations.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.update_transaction` instead.
Parameters
----------
transaction_id : str
Transaction ID.
commit : Optional[bool]
Commit transaction?
rollback : Optional[bool]
Rollback transaction?
Returns
-------
Transaction
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions/{transactionId}'
api_params = {}
if transaction_id is None or transaction_id == '':
raise AppwriteException('Missing required parameter: "transaction_id"')
api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id)))
if commit is not None:
api_params['commit'] = self._normalize_value(commit)
if rollback is not None:
api_params['rollback'] = self._normalize_value(rollback)
response = self.client.call(
'patch',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Transaction)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_transaction` instead.")
def delete_transaction(
self,
transaction_id: str,
) -> Dict[str, Any]:
"""
Delete a transaction by its unique ID.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.delete_transaction` instead.
Parameters
----------
transaction_id : str
Transaction ID.
Returns
-------
Dict[str, Any]
API response as a dictionary
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions/{transactionId}'
api_params = {}
if transaction_id is None or transaction_id == '':
raise AppwriteException('Missing required parameter: "transaction_id"')
api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id)))
response = self.client.call(
'delete',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return response
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_operations` instead.")
def create_operations(
self,
transaction_id: str,
operations: Optional[List[Dict[str, Any]]] = None,
) -> Transaction:
"""
Create multiple operations in a single transaction.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.create_operations` instead.
Parameters
----------
transaction_id : str
Transaction ID.
operations : Optional[List[Dict[str, Any]]]
Array of staged operations.
Returns
-------
Transaction
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/transactions/{transactionId}/operations'
api_params = {}
if transaction_id is None or transaction_id == '':
raise AppwriteException('Missing required parameter: "transaction_id"')
api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id)))
if operations is not None:
api_params['operations'] = self._normalize_value(operations)
response = self.client.call(
'post',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Transaction)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get` instead.")
def get(
self,
database_id: str,
) -> Database:
"""
Get a database by its unique ID. This endpoint response returns a JSON object with the database metadata.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.get` instead.
Parameters
----------
database_id : str
Database ID.
Returns
-------
Database
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Database)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update` instead.")
def update(
self,
database_id: str,
name: Optional[str] = None,
enabled: Optional[bool] = None,
description: Optional[str] = None,
) -> Database:
"""
Update a database by its unique ID.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.update` instead.
Parameters
----------
database_id : str
Database ID.
name : Optional[str]
Database name. Max length: 128 chars.
enabled : Optional[bool]
Is database enabled? When set to 'disabled', users cannot access the database but Server SDKs with an API key can still read and write to the database. No data is lost when this is toggled.
description : Optional[str]
Optional description for the database.
Returns
-------
Database
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
if name is not None:
api_params['name'] = self._normalize_value(name)
if enabled is not None:
api_params['enabled'] = self._normalize_value(enabled)
if description is not None:
api_params['description'] = self._normalize_value(description)
response = self.client.call(
'put',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Database)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete` instead.")
def delete(
self,
database_id: str,
) -> Dict[str, Any]:
"""
Delete a database by its unique ID. Only API keys with with databases.write scope can delete a database.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.delete` instead.
Parameters
----------
database_id : str
Database ID.
Returns
-------
Dict[str, Any]
API response as a dictionary
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
response = self.client.call(
'delete',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return response
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_tables` instead.")
def list_collections(
self,
database_id: str,
queries: Optional[List[str]] = None,
search: Optional[str] = None,
total: Optional[bool] = None,
) -> CollectionList:
"""
Get a list of all collections that belong to the provided databaseId. You can use the search parameter to filter your results.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.list_tables` instead.
Parameters
----------
database_id : str
Database ID.
queries : Optional[List[str]]
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, enabled, documentSecurity
search : Optional[str]
Search term to filter your list results. Max length: 256 chars.
total : Optional[bool]
When set to false, the total count returned will be 0 and will not be calculated.
Returns
-------
CollectionList
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
if queries is not None:
api_params['queries'] = self._normalize_value(queries)
if search is not None:
api_params['search'] = self._normalize_value(search)
if total is not None:
api_params['total'] = self._normalize_value(total)
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=CollectionList)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_table` instead.")
def create_collection(
self,
database_id: str,
collection_id: str,
name: str,
permissions: Optional[List[str]] = None,
document_security: Optional[bool] = None,
enabled: Optional[bool] = None,
attributes: Optional[List[Dict[str, Any]]] = None,
indexes: Optional[List[Dict[str, Any]]] = None,
description: Optional[str] = None,
) -> Collection:
"""
Create a new Collection. Before using this route, you should create a new database resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.create_table` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. 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 : str
Collection name. Max length: 128 chars.
permissions : Optional[List[str]]
An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).
document_security : Optional[bool]
Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).
enabled : Optional[bool]
Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.
attributes : Optional[List[Dict[str, Any]]]
Array of attribute definitions to create. Each attribute should contain: key (string), type (string: string, varchar, text, mediumtext, longtext, integer, bigint, double, boolean, datetime, point, linestring, polygon, email, url, ip, enum), size (integer, required for string and varchar types), required (boolean, optional), default (mixed, optional), array (boolean, optional), and type-specific options.
indexes : Optional[List[Dict[str, Any]]]
Array of index definitions to create. Each index should contain: key (string), type (string: key, fulltext, unique, spatial, trigram), attributes (array of attribute keys), orders (array of ASC/DESC, optional), and lengths (array of integers, optional).
description : Optional[str]
Optional description for the collection.
Returns
-------
Collection
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
if collection_id is None:
raise AppwriteException('Missing required parameter: "collection_id"')
if name is None:
raise AppwriteException('Missing required parameter: "name"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
api_params['collectionId'] = self._normalize_value(collection_id)
api_params['name'] = self._normalize_value(name)
if permissions is not None:
api_params['permissions'] = self._normalize_value(permissions)
if document_security is not None:
api_params['documentSecurity'] = self._normalize_value(document_security)
if enabled is not None:
api_params['enabled'] = self._normalize_value(enabled)
if attributes is not None:
api_params['attributes'] = self._normalize_value(attributes)
if indexes is not None:
api_params['indexes'] = self._normalize_value(indexes)
if description is not None:
api_params['description'] = self._normalize_value(description)
response = self.client.call(
'post',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Collection)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_table` instead.")
def get_collection(
self,
database_id: str,
collection_id: str,
) -> Collection:
"""
Get a collection by its unique ID. This endpoint response returns a JSON object with the collection metadata.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.get_table` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Collection ID.
Returns
-------
Collection
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections/{collectionId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
if collection_id is None or collection_id == '':
raise AppwriteException('Missing required parameter: "collection_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id)))
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Collection)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_table` instead.")
def update_collection(
self,
database_id: str,
collection_id: str,
name: Optional[str] = None,
permissions: Optional[List[str]] = None,
document_security: Optional[bool] = None,
enabled: Optional[bool] = None,
purge: Optional[bool] = None,
description: Optional[str] = None,
) -> Collection:
"""
Update a collection by its unique ID.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.update_table` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Collection ID.
name : Optional[str]
Collection name. Max length: 128 chars.
permissions : Optional[List[str]]
An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).
document_security : Optional[bool]
Enables configuring permissions for individual documents. A user needs one of document or collection level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).
enabled : Optional[bool]
Is collection enabled? When set to 'disabled', users cannot access the collection but Server SDKs with and API key can still read and write to the collection. No data is lost when this is toggled.
purge : Optional[bool]
When true, purge all cached list responses for this collection as part of the update. Use this to force readers to see fresh data immediately instead of waiting for the cache TTL to expire.
description : Optional[str]
Optional description for the collection.
Returns
-------
Collection
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections/{collectionId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
if collection_id is None or collection_id == '':
raise AppwriteException('Missing required parameter: "collection_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id)))
if name is not None:
api_params['name'] = self._normalize_value(name)
if permissions is not None:
api_params['permissions'] = self._normalize_value(permissions)
if document_security is not None:
api_params['documentSecurity'] = self._normalize_value(document_security)
if enabled is not None:
api_params['enabled'] = self._normalize_value(enabled)
if purge is not None:
api_params['purge'] = self._normalize_value(purge)
if description is not None:
api_params['description'] = self._normalize_value(description)
response = self.client.call(
'put',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=Collection)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_table` instead.")
def delete_collection(
self,
database_id: str,
collection_id: str,
) -> Dict[str, Any]:
"""
Delete a collection by its unique ID. Only users with write permissions have access to delete this resource.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.delete_table` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Collection ID.
Returns
-------
Dict[str, Any]
API response as a dictionary
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections/{collectionId}'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
if collection_id is None or collection_id == '':
raise AppwriteException('Missing required parameter: "collection_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id)))
response = self.client.call(
'delete',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'content-type': 'application/json',
'accept': 'application/json',
},
api_params,
)
return response
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_columns` instead.")
def list_attributes(
self,
database_id: str,
collection_id: str,
queries: Optional[List[str]] = None,
total: Optional[bool] = None,
) -> AttributeList:
"""
List attributes in the collection.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.list_columns` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Collection ID.
queries : Optional[List[str]]
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: key, type, size, required, array, status, error
total : Optional[bool]
When set to false, the total count returned will be 0 and will not be calculated.
Returns
-------
AttributeList
API response as a typed Pydantic model
Raises
------
AppwriteException
If API request fails
"""
api_path = '/databases/{databaseId}/collections/{collectionId}/attributes'
api_params = {}
if database_id is None or database_id == '':
raise AppwriteException('Missing required parameter: "database_id"')
if collection_id is None or collection_id == '':
raise AppwriteException('Missing required parameter: "collection_id"')
api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id)))
api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id)))
if queries is not None:
api_params['queries'] = self._normalize_value(queries)
if total is not None:
api_params['total'] = self._normalize_value(total)
response = self.client.call(
'get',
api_path,
{
'X-Appwrite-Project': self.client.get_config('project'),
'accept': 'application/json',
},
api_params,
)
return self._parse_response(response, model=AttributeList)
@deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_big_int_column` instead.")
def create_big_int_attribute(
self,
database_id: str,
collection_id: str,
key: str,
required: bool,
min: Optional[float] = None,
max: Optional[float] = None,
default: Optional[float] = None,
array: Optional[bool] = None,
description: Optional[str] = None,
) -> AttributeBigint:
"""
Create a bigint attribute. Optionally, minimum and maximum values can be provided.
.. deprecated::1.8.0
This API has been deprecated since 1.8.0. Please use `tablesDB.create_big_int_column` instead.
Parameters
----------
database_id : str
Database ID.
collection_id : str
Collection ID.
key : str
Attribute Key.
required : bool
Is attribute required?
min : Optional[float]
Minimum value
max : Optional[float]
Maximum value
default : Optional[float]
You can’t perform that action at this time.
