8000 🚀 Feature: sdk for setup single database of project by default · Issue #5773 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🚀 Feature: sdk for setup single database of project by default #5773

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

Closed
2 tasks done
TechComet opened this issue Jul 5, 2023 · 6 comments
Closed
2 tasks done

🚀 Feature: sdk for setup single database of project by default #5773

TechComet opened this issue Jul 5, 2023 · 6 comments
Labels
product / databases Fixes and upgrades for the Appwrite Database.

Comments

@TechComet
Copy link
TechComet commented Jul 5, 2023

🔖 Feature description

Most projects use a single database

I write example for getDocument but I talk for all functions

and write class for call function direct with default client
samething like this class but inside appwrite package

https://pastebin.com/raw/txMGE7Bh

🎤 Pitch

example in Dart

Client client = Client();
client
    .setEndpoint(appwriteEndpoint)
    .setProject(appwriteProjectId)
    .setDefaultDatabase('defaultdb')
    .setSelfSigned(status: appwriteSelfSigned);

in get document if use default database databaseId is null
database.getDocument(collectionId: 'collectionId', documentId: 'documentId');
in get document if use other database
database.getDocument(databaseId: 'other databaseId', collectionId: 'collectionId', documentId: 'documentId')

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@safwanyp
Copy link
Contributor
safwanyp commented Jul 6, 2023

Trying to understand this concept.

So you are suggesting that we should be able to set the default database in your project while initializing your client right?

If that's the case, then I can see why this can be useful, but it seems like a not-so-necessary thing. You're absolutely right when saying that most projects use a single DB, but countless others use multiple as well. This can be countered by making the setDefaultDatabase call optional, but I still don't see much value in adding something like this.

Might be completely wrong though. Just my opinion!

@TechComet
Copy link
Author

Ease of use
Code abbreviation
It will be possible to select a database within the function as it is now so the old code will not be broken

@TechComet
Copy link
Author
TechComet commented Jul 6, 2023

anyone can use single database or multi project
but if not use databaseId parameter in getDocument use default database
(see example in first comment)

and in create functions use documentId optional (if null use ID.unique() default)

yes
setDefaultDatabase call optional

@byawitz
Copy link
Member
byawitz commented Jul 7, 2023

You can see that in an older version of Appwrite, this for example there wasn't even a layer of Database per project.

The Database layer was added in version 0.15, check here more about that.

What I think can be a way around it is to wrap those functions in some small helper. For example:

class ProjectDB {
  String databaseID;
  Databases database;

  ProjectDB({this.databaseID = '', Client client}) {
    database = Databases(client);
  }

  Future<models.DocumentList> listDocuments({required String collectionId, List<String>? queries}) async {
    
    return await databases.listDocuments(
        databaseId: databaseID,
        collectionId: collectionId,
        queries: queries
    );
  }
}

Although I agree that it would be nice to have something like you've suggested, like:

databases.setDefaultDB(databaseId);

// Use Default
await databases.listDocuments(
        collectionId: collectionId,
        queries: queries
    );

// Specify DB
await databases.listDocuments(
        databaseId: databaseID,
        collectionId: collectionId,
        queries: queries
    );

@safwanyp
Copy link
Contributor
safwanyp commented Jul 7, 2023

Reading @byawitz comment made it more clear to me.

+1 from me.

@stnguyen90
Copy link
Contributor

@TechComet, thanks for raising this! 🙏🏼

We actually had a way to set the databaseId for all requests in the past, but this lead to more confusion especially when trying to explain how creating databases worked (with a server SDK). That's why we changed the SDKs to explicitly require a databaseId parameter. This is a bit more repetitive, but being explicit avoids confusion.

As @byawitz mentioned in #5773 (comment), you're more than welcome to create a wrapper in your code.

@stnguyen90 stnguyen90 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2023
@stnguyen90 stnguyen90 added the product / databases Fixes and upgrades for the Appwrite Database. label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product / databases Fixes and upgrades for the Appwrite Database.
Projects
None yet
Development

No branches or pull requests

4 participants
0