Skip to content

Refacting databases & removed redundancy #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Once your SDK header is set, create the Appwrite service objects and choose the

// for the Databases instance
Databases& databases = appwrite.getDatabases();
databases.setup(apiKey, projectId);
```

### Full Example
Expand All @@ -77,11 +76,9 @@ int main() {
std::string name = "<unique-database-name>";
bool enabled = true;

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();
Appwrite appwrite(projectId, apiKey);

databases.setup(apiKey, projectId);
std::string response = databases.create(databaseId, name, enabled);
std::string response = appwrite.getDatabases().create(databaseId, name, enabled);

return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ int main() {
bool defaultValue = true;
bool required = true;

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required);
std::string response = appwrite.getDatabases().createBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required);
std::cout << "Boolean attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ int main() {
bool required = true;
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue);
std::string response = appwrite.getDatabases().createEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue);
std::cout << "Email attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ int main() {
std::string defaultValue = "";
std::vector<std::string> elements = {"element123"};

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements);
std::string response = appwrite.getDatabases().createEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements);
std::cout << "Enum attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ int main() {
double max = 100.0;
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
std::string response = appwrite.getDatabases().createFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
std::cout << "Float attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ int main() {
bool required = true;
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue);
std::string response = appwrite.getDatabases().createIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue);
std::cout << "IP Addresss attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ int main() {
int max = 100;
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
std::string response = appwrite.getDatabases().createIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue);
std::cout << "Integer attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ int main() {
std::vector<std::string> elements = {"element123"};
int size = 255;

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size);
std::string response = appwrite.getDatabases().createStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size);
std::cout << "String attribute created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/attribute/listAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ int main() {
std::string databaseId = "database123";
std::string collectionId = "test1234";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.listAttributes(databaseId, collectionId);
std::string response = appwrite.getDatabases().listAttributes(databaseId, collectionId);
std::cout << "Attributes listed successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ int main() {
bool defaultValue = false;
bool required = false;

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required, new_key);
std::string response = appwrite.getDatabases().updateBooleanAttribute(databaseId, collectionId, attributeId, defaultValue, required, new_key);
std::cout << "Boolean attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ int main() {
std::string new_key = "new_email_attribute";
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
std::string response = appwrite.getDatabases().updateEmailAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
std::cout << "Email attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ int main() {
std::vector<std::string> elements = {"element1234"};
std::string new_key = "new_enum_attribute";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, new_key);
std::string response = appwrite.getDatabases().updateEnumAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, new_key);
std::cout << "Enum attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ int main() {
std::string defaultValue = "";
std::string new_key = "UpdatedFloat123";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
std::string response = appwrite.getDatabases().updateFloatAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
std::cout << "Float attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ int main() {
std::string new_key = "UpdatedIPaddress123";
std::string defaultValue = "";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
std::string response = appwrite.getDatabases().updateIPaddressAttribute(databaseId, collectionId, attributeId, required, defaultValue, new_key);
std::cout << "IP Address attribute updated successfully!\nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Appwrite exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ int main() {
std::string defaultValue = "";
std::string new_key = "UpdatedInteger123";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
std::string response = appwrite.getDatabases().updateIntegerAttribute(databaseId, collectionId, attributeId, required, min, max, defaultValue, new_key);
std::cout << "Integer attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ int main() {
int size = 5;
std::string new_key = "UpdatedString123";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.updateStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size, new_key);
std::string response = appwrite.getDatabases().updateStringAttribute(databaseId, collectionId, attributeId, required, defaultValue, elements, size, new_key);
std::cout << "String attribute updated successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/createCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ int main() {
std::string name = "samplecollection";
bool enabled = true;

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.createCollection(databaseId, collectionId, name, enabled);
std::string response = appwrite.getDatabases().createCollection(databaseId, collectionId, name, enabled);
std::cout << "Collection created successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/deleteCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ int main() {
std::string databaseId = "database123";
std::string collectionId = "test123";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.deleteCollection(databaseId, collectionId);
std::string response = appwrite.getDatabases().deleteCollection(databaseId, collectionId);
std::cout << "collection deleted successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/document/createDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ int main()
{"UpdatedString123", {"abc", "def"}}
};

Appwrite appwrite(projectId);
Databases &databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try
{
std::string response = databases.createDocument(databaseId, collectionId, documentId, data);
std::string response = appwrite.getDatabases().createDocument(databaseId, collectionId, documentId, data);
std::cout << "Document created successfully! \nResponse: " << response << std::endl;
}
catch (const AppwriteException &ex)
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/document/deleteDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ int main() {
std::string collectionId = "test1234";
std::string documentId = "document1234";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.deleteDocument(databaseId, collectionId, documentId);
std::string response = appwrite.getDatabases().deleteDocument(databaseId, collectionId, documentId);
std::cout << "document deleted successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/document/getDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ int main() {
std::string collectionId = "test1234";
std::string documentId = "document123";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.getDocument(databaseId, collectionId, documentId);
std::string response = appwrite.getDatabases().getDocument(databaseId, collectionId, documentId);
std::cout << "Document fetched successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/document/listDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ int main() {
std::string databaseId = "database123";
std::string collectionId = "test1234";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.listDocument(databaseId, collectionId);
std::string response = appwrite.getDatabases().listDocument(databaseId, collectionId);
std::cout << "Documents listed successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/getCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ int main() {
std::string databaseId = "database123";
std::string collectionId = "test1234";

Appwrite appwrite(projectId);
Databases& databases = appwrite.getDatabases();

databases.setup(apiKey, projectId);
Appwrite appwrite(projectId, apiKey);

try {
std::string response = databases.getCollection(databaseId, collectionId);
std::string response = appwrite.getDatabases().getCollection(databaseId, collectionId);
std::cout << "Collection fetched successfully! \nResponse: " << response << std::endl;
} catch (const AppwriteException& ex) {
std::cerr << "Exception: " << ex.what() << std::endl;
Expand Down
7 changes: 2 additions & 5 deletions examples/database/collection/indexes/createIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ int main() {
std::string projectId = "66fbb5a100070a3a1d19";
std::string apiKey = "";

Appwrite appwrite(projectId);
Databases& database = appwrite.getDatabases();
Appwrite appwrite(projectId, apiKey);

std::string databaseId = "database123";
std::string collectionId = "test1234";
Expand All @@ -15,11 +14,9 @@ int main() {
// we need to use type as "key" for arrayed attributes
std::string type = "key";
std::vector<std::string> attributes = {"new_enum_attribute"};

database.setup(apiKey, projectId);

try {
std::string response = database.createIndexes(
std::string response = appwrite.getDatabases().createIndexes(
databaseId, collectionId,key, type, attributes
);
std::cout << "Index created successfully! \nResponse: " << response << std::endl;
Expand Down
Loading