sdk-for-flutter icon indicating copy to clipboard operation
sdk-for-flutter copied to clipboard

🐛 Bug Report: Missing `create` function for databases.

Open Vildnex opened this issue 1 year ago • 1 comments

👟 Reproduction steps

Trying to call the following code from this documentation:

import 'package:dart_appwrite/dart_appwrite.dart';

void main() { // Init SDK
  Client client = Client();
  Databases databases = Databases(client);

  client
    .setEndpoint('https://<MY_LOCAL_IP>/v1') // Your API Endpoint
    .setProject('<ID_PROJECT>) // Your project ID
    .setKey('<SECRET_KEY>) // Your secret API key
  ;

  Future result = databases.create(
    databaseId: '<DATABASE_ID>',
    name: '<NAME>',
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}

👍 Expected behavior

I would expect that code to create a new database with a specific ID and NAME.

👎 Actual Behavior

But instead, I will get the following error message:

The method 'setKey' isn't defined for the type 'Client'. (Documentation) Try correcting the name to the name of an existing method, or defining a method named 'setKey'.

The method 'create' isn't defined for the type 'Databases'. (Documentation) Try correcting the name to the name of an existing method, or defining a method named 'create'.

🎲 Appwrite version

Version 2.0.x

💻 Operating system

Linux

🧱 Your Environment

I use Appwrite the the docker-compose file provided from the official documentation with the .env file from the same official documentation.

appwrite: ^12.0.4 Flutter 3.22.2 Tools • Dart 3.4.3 • DevTools 2.34.3

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

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Vildnex avatar Jun 28 '24 09:06 Vildnex

I also have the same problem with the code to generate new collections:

import 'package:dart_appwrite/dart_appwrite.dart';

void main() { // Init SDK
  Client client = Client();
  Databases databases = Databases(client);

  client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
  ;

  Future result = databases.createCollection(
    databaseId: '<DATABASE_ID>',
    collectionId: '[COLLECTION_ID]',
    name: '[NAME]',
  );

  result
    .then((response) {
      print(response);
    }).catchError((error) {
      print(error.response);
  });
}

error:

The method 'createCollection' isn't defined for the type 'Databases'. (Documentation) Try correcting the name to the name of an existing method, or defining a method named 'createCollection'.

Vildnex avatar Jun 28 '24 09:06 Vildnex

@Vildnex, thanks for raising this issue! 🙏🏼

The Flutter SDK (appwrite) is a client SDK and doesn't expose server-side operations like creating collections. If you want to create collections, you need to use the Dart SDK (dart_appwrite), which is a server SDK, and should only be used server-side, not in an app.

stnguyen90 avatar Jul 04 '24 00:07 stnguyen90

Oh.. Now make sense, sorry for opening this issue in this case.

Thanks for the explanation :D

Vildnex avatar Jul 16 '24 10:07 Vildnex