Skip to content

Commit 8f6299d

Browse files
committed
updated databases & removed redundancy
1 parent 717f596 commit 8f6299d

35 files changed

+73
-185
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ Once your SDK header is set, create the Appwrite service objects and choose the
6262

6363
// for the Databases instance
6464
Databases& databases = appwrite.getDatabases();
65-
databases.setup(apiKey, projectId);
6665
```
6766
6867
### Full Example
@@ -77,11 +76,9 @@ int main() {
7776
std::string name = "<unique-database-name>";
7877
bool enabled = true;
7978
80-
Appwrite appwrite(projectId);
81-
Databases& databases = appwrite.getDatabases();
79+
Appwrite appwrite(projectId, apiKey);
8280
83-
databases.setup(apiKey, projectId);
84-
std::string response = databases.create(databaseId, name, enabled);
81+
std::string response = appwrite.getDatabases().create(databaseId, name, enabled);
8582
8683
return 0;
8784
}

examples/database/collection/attribute/createBooleanAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ int main() {
1010
bool defaultValue = true;
1111
bool required = true;
1212

13-
Appwrite appwrite(projectId);
14-
Databases& databases = appwrite.getDatabases();
15-
16-
databases.setup(apiKey, projectId);
13+
Appwrite appwrite(projectId, apiKey);
1714

1815
try {
19-
std::string response = databases.createBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required);
16+
std::string response = appwrite.getDatabases().createBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required);
2017
std::cout << "Boolean attribute created successfully! \nResponse: " << response << std::endl;
2118
} catch (const AppwriteException& ex) {
2219
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createEmailAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ int main() {
1010
bool required = true;
1111
std::string defaultValue = "";
1212

13-
Appwrite appwrite(projectId);
14-
Databases& databases = appwrite.getDatabases();
15-
16-
databases.setup(apiKey, projectId);
13+
Appwrite appwrite(projectId, apiKey);
1714

1815
try {
19-
std::string response = databases.createEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue);
16+
std::string response = appwrite.getDatabases().createEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue);
2017
std::cout << "Email attribute created successfully! \nResponse: " << response << std::endl;
2118
} catch (const AppwriteException& ex) {
2219
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createEnumAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ int main() {
1111
std::string defaultValue = "";
1212
std::vector<std::string> elements = {"element123"};
1313

14-
Appwrite appwrite(projectId);
15-
Databases& databases = appwrite.getDatabases();
16-
17-
databases.setup(apiKey, projectId);
14+
Appwrite appwrite(projectId, apiKey);
1815

1916
try {
20-
std::string response = databases.createEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements);
17+
std::string response = appwrite.getDatabases().createEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements);
2118
std::cout << "Enum attribute created successfully! \nResponse: " << response << std::endl;
2219
} catch (const AppwriteException& ex) {
2320
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createFloatAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ int main() {
1212
double max = 100.0;
1313
std::string defaultValue = "";
1414

15-
Appwrite appwrite(projectId);
16-
Databases& databases = appwrite.getDatabases();
17-
18-
databases.setup(apiKey, projectId);
15+
Appwrite appwrite(projectId, apiKey);
1916

2017
try {
21-
std::string response = databases.createFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
18+
std::string response = appwrite.getDatabases().createFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
2219
std::cout << "Float attribute created successfully! \nResponse: " << response << std::endl;
2320
} catch (const AppwriteException& ex) {
2421
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createIPaddressAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ int main() {
1010
bool required = true;
1111
std::string defaultValue = "";
1212

13-
Appwrite appwrite(projectId);
14-
Databases& databases = appwrite.getDatabases();
15-
16-
databases.setup(apiKey, projectId);
13+
Appwrite appwrite(projectId, apiKey);
1714

1815
try {
19-
std::string response = databases.createIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue);
16+
std::string response = appwrite.getDatabases().createIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue);
2017
std::cout << "IP Addresss attribute created successfully! \nResponse: " << response << std::endl;
2118
} catch (const AppwriteException& ex) {
2219
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createIntegerAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ int main() {
1212
int max = 100;
1313
std::string defaultValue = "";
1414

15-
Appwrite appwrite(projectId);
16-
Databases& databases = appwrite.getDatabases();
17-
18-
databases.setup(apiKey, projectId);
15+
Appwrite appwrite(projectId, apiKey);
1916

2017
try {
21-
std::string response = databases.createIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
18+
std::string response = appwrite.getDatabases().createIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
2219
std::cout << "Integer attribute created successfully! \nResponse: " << response << std::endl;
2320
} catch (const AppwriteException& ex) {
2421
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/createStringAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ int main() {
1212
std::vector<std::string> elements = {"element123"};
1313
int size = 255;
1414

15-
Appwrite appwrite(projectId);
16-
Databases& databases = appwrite.getDatabases();
17-
18-
databases.setup(apiKey, projectId);
15+
Appwrite appwrite(projectId, apiKey);
1916

2017
try {
21-
std::string response = databases.createStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size);
18+
std::string response = appwrite.getDatabases().createStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size);
2219
std::cout << "String attribute created successfully! \nResponse: " << response << std::endl;
2320
} catch (const AppwriteException& ex) {
2421
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/listAttributes.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ int main() {
77
std::string databaseId = "database123";
88
std::string collectionId = "test1234";
99

10-
Appwrite appwrite(projectId);
11-
Databases& databases = appwrite.getDatabases();
12-
13-
databases.setup(apiKey, projectId);
10+
Appwrite appwrite(projectId, apiKey);
1411

1512
try {
16-
std::string response = databases.listAttributes(databaseId, collectionId);
13+
std::string response = appwrite.getDatabases().listAttributes(databaseId, collectionId);
1714
std::cout << "Attributes listed successfully! \nResponse: " << response << std::endl;
1815
} catch (const AppwriteException& ex) {
1916
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateBooleanAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ int main() {
1111
bool defaultValue = false;
1212
bool required = false;
1313

14-
Appwrite appwrite(projectId);
15-
Databases& databases = appwrite.getDatabases();
16-
17-
databases.setup(apiKey, projectId);
14+
Appwrite appwrite(projectId, apiKey);
1815

1916
try {
20-
std::string response = databases.updateBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required, new_key);
17+
std::string response = appwrite.getDatabases().updateBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required, new_key);
2118
std::cout << "Boolean attribute updated successfully! \nResponse: " << response << std::endl;
2219
} catch (const AppwriteException& ex) {
2320
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateEmailAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ int main() {
1111
std::string new_key = "new_email_attribute";
1212
std::string defaultValue = "";
1313

14-
Appwrite appwrite(projectId);
15-
Databases& databases = appwrite.getDatabases();
16-
17-
databases.setup(apiKey, projectId);
14+
Appwrite appwrite(projectId, apiKey);
1815

1916
try {
20-
std::string response = databases.updateEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
17+
std::string response = appwrite.getDatabases().updateEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
2118
std::cout << "Email attribute updated successfully! \nResponse: " << response << std::endl;
2219
} catch (const AppwriteException& ex) {
2320
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateEnumAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@ int main() {
1212
std::vector<std::string> elements = {"element1234"};
1313
std::string new_key = "new_enum_attribute";
1414

15-
Appwrite appwrite(projectId);
16-
Databases& databases = appwrite.getDatabases();
17-
18-
databases.setup(apiKey, projectId);
15+
Appwrite appwrite(projectId, apiKey);
1916

2017
try {
21-
std::string response = databases.updateEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, new_key);
18+
std::string response = appwrite.getDatabases().updateEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, new_key);
2219
std::cout << "Enum attribute updated successfully! \nResponse: " << response << std::endl;
2320
} catch (const AppwriteException& ex) {
2421
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateFloatAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ int main() {
1313
std::string defaultValue = "";
1414
std::string new_key = "UpdatedFloat123";
1515

16-
Appwrite appwrite(projectId);
17-
Databases& databases = appwrite.getDatabases();
18-
19-
databases.setup(apiKey, projectId);
16+
Appwrite appwrite(projectId, apiKey);
2017

2118
try {
22-
std::string response = databases.updateFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
19+
std::string response = appwrite.getDatabases().updateFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
2320
std::cout << "Float attribute updated successfully! \nResponse: " << response << std::endl;
2421
} catch (const AppwriteException& ex) {
2522
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateIPaddressAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ int main() {
1111
std::string new_key = "UpdatedIPaddress123";
1212
std::string defaultValue = "";
1313

14-
Appwrite appwrite(projectId);
15-
Databases& databases = appwrite.getDatabases();
16-
17-
databases.setup(apiKey, projectId);
14+
Appwrite appwrite(projectId, apiKey);
1815

1916
try {
20-
std::string response = databases.updateIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
17+
std::string response = appwrite.getDatabases().updateIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
2118
std::cout << "IP Address attribute updated successfully!\nResponse: " << response << std::endl;
2219
} catch (const AppwriteException& ex) {
2320
std::cerr << "Appwrite exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateIntegerAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@ int main() {
1313
std::string defaultValue = "";
1414
std::string new_key = "UpdatedInteger123";
1515

16-
Appwrite appwrite(projectId);
17-
Databases& databases = appwrite.getDatabases();
18-
19-
databases.setup(apiKey, projectId);
16+
Appwrite appwrite(projectId, apiKey);
2017

2118
try {
22-
std::string response = databases.updateIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
19+
std::string response = appwrite.getDatabases().updateIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
2320
std::cout << "Integer attribute updated successfully! \nResponse: " << response << std::endl;
2421
} catch (const AppwriteException& ex) {
2522
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/attribute/updateStringAttribute.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ int main() {
1414
int size = 5;
1515
std::string new_key = "UpdatedString123";
1616

17-
Appwrite appwrite(projectId);
18-
Databases& databases = appwrite.getDatabases();
19-
20-
databases.setup(apiKey, projectId);
17+
Appwrite appwrite(projectId, apiKey);
2118

2219
try {
23-
std::string response = databases.updateStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size, new_key);
20+
std::string response = appwrite.getDatabases().updateStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size, new_key);
2421
std::cout << "String attribute updated successfully! \nResponse: " << response << std::endl;
2522
} catch (const AppwriteException& ex) {
2623
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/createCollection.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ int main() {
99
std::string name = "samplecollection";
1010
bool enabled = true;
1111

12-
Appwrite appwrite(projectId);
13-
Databases& databases = appwrite.getDatabases();
14-
15-
databases.setup(apiKey, projectId);
12+
Appwrite appwrite(projectId, apiKey);
1613

1714
try {
18-
std::string response = databases.createCollection(databaseId, collectionId, name, enabled);
15+
std::string response = appwrite.getDatabases().createCollection(databaseId, collectionId, name, enabled);
1916
std::cout << "Collection created successfully! \nResponse: " << response << std::endl;
2017
} catch (const AppwriteException& ex) {
2118
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/deleteCollection.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ int main() {
77
std::string databaseId = "database123";
88
std::string collectionId = "test123";
99

10-
Appwrite appwrite(projectId);
11-
Databases& databases = appwrite.getDatabases();
12-
13-
databases.setup(apiKey, projectId);
10+
Appwrite appwrite(projectId, apiKey);
1411

1512
try {
16-
std::string response = databases.deleteCollection(databaseId, collectionId);
13+
std::string response = appwrite.getDatabases().deleteCollection(databaseId, collectionId);
1714
std::cout << "collection deleted successfully! \nResponse: " << response << std::endl;
1815
} catch (const AppwriteException& ex) {
1916
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/document/createDocument.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ int main()
1818
{"UpdatedString123", {"abc", "def"}}
1919
};
2020

21-
Appwrite appwrite(projectId);
22-
Databases &databases = appwrite.getDatabases();
23-
24-
databases.setup(apiKey, projectId);
21+
Appwrite appwrite(projectId, apiKey);
2522

2623
try
2724
{
28-
std::string response = databases.createDocument(databaseId, collectionId, documentId, data);
25+
std::string response = appwrite.getDatabases().createDocument(databaseId, collectionId, documentId, data);
2926
std::cout << "Document created successfully! \nResponse: " << response << std::endl;
3027
}
3128
catch (const AppwriteException &ex)

examples/database/collection/document/deleteDocument.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ int main() {
88
std::string collectionId = "test1234";
99
std::string documentId = "document1234";
1010

11-
Appwrite appwrite(projectId);
12-
Databases& databases = appwrite.getDatabases();
13-
14-
databases.setup(apiKey, projectId);
11+
Appwrite appwrite(projectId, apiKey);
1512

1613
try {
17-
std::string response = databases.deleteDocument(databaseId, collectionId, documentId);
14+
std::string response = appwrite.getDatabases().deleteDocument(databaseId, collectionId, documentId);
1815
std::cout << "document deleted successfully! \nResponse: " << response << std::endl;
1916
} catch (const AppwriteException& ex) {
2017
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/document/getDocument.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ int main() {
88
std::string collectionId = "test1234";
99
std::string documentId = "document123";
1010

11-
Appwrite appwrite(projectId);
12-
Databases& databases = appwrite.getDatabases();
13-
14-
databases.setup(apiKey, projectId);
11+
Appwrite appwrite(projectId, apiKey);
1512

1613
try {
17-
std::string response = databases.getDocument(databaseId, collectionId, documentId);
14+
std::string response = appwrite.getDatabases().getDocument(databaseId, collectionId, documentId);
1815
std::cout << "Document fetched successfully! \nResponse: " << response << std::endl;
1916
} catch (const AppwriteException& ex) {
2017
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/document/listDocument.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ int main() {
77
std::string databaseId = "database123";
88
std::string collectionId = "test1234";
99

10-
Appwrite appwrite(projectId);
11-
Databases& databases = appwrite.getDatabases();
12-
13-
databases.setup(apiKey, projectId);
10+
Appwrite appwrite(projectId, apiKey);
1411

1512
try {
16-
std::string response = databases.listDocument(databaseId, collectionId);
13+
std::string response = appwrite.getDatabases().listDocument(databaseId, collectionId);
1714
std::cout << "Documents listed successfully! \nResponse: " << response << std::endl;
1815
} catch (const AppwriteException& ex) {
1916
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/getCollection.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ int main() {
77
std::string databaseId = "database123";
88
std::string collectionId = "test1234";
99

10-
Appwrite appwrite(projectId);
11-
Databases& databases = appwrite.getDatabases();
12-
13-
databases.setup(apiKey, projectId);
10+
Appwrite appwrite(projectId, apiKey);
1411

1512
try {
16-
std::string response = databases.getCollection(databaseId, collectionId);
13+
std::string response = appwrite.getDatabases().getCollection(databaseId, collectionId);
1714
std::cout << "Collection fetched successfully! \nResponse: " << response << std::endl;
1815
} catch (const AppwriteException& ex) {
1916
std::cerr << "Exception: " << ex.what() << std::endl;

examples/database/collection/indexes/createIndex.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ int main() {
55
std::string projectId = "66fbb5a100070a3a1d19";
66
std::string apiKey = "";
77

8-
Appwrite appwrite(projectId);
9-
Databases& database = appwrite.getDatabases();
8+
Appwrite appwrite(projectId, apiKey);
109

1110
std::string databaseId = "database123";
1211
std::string collectionId = "test1234";
@@ -15,11 +14,9 @@ int main() {
1514
// we need to use type as "key" for arrayed attributes
1615
std::string type = "key";
1716
std::vector<std::string> attributes = {"new_enum_attribute"};
18-
19-
database.setup(apiKey, projectId);
2017

2118
try {
22-
std::string response = database.createIndexes(
19+
std::string response = appwrite.getDatabases().createIndexes(
2320
databaseId, collectionId,key, type, attributes
2421
);
2522
std::cout << "Index created successfully! \nResponse: " << response << std::endl;

0 commit comments

Comments
 (0)