Skip to content

Storage

The schmuckliCloud service provides different kind of services. Therefore, all the services are splitted in to different packages, so that you only have to install these packages, which you want to use in your project. In this documentation, it's all about the storage package.

Getting started

To install the package, just add the following line in your existing pubspec.yaml file under dependencies:

dependencies:
    schmucklicloud_storage: <SELECT THE NEWEST VERSION>

After that, just install the package on your local machine via the command:

pub get

Setup in your project

Before you can use the function inside of your project, you also have to import the package in your file, where you will using the service.

//Import the package
import 'package:schmucklicloud_storage/main.dart';

//Setup a referene
sCStorage reference = new sCStorage("<YOUR_APP_ID>", "<YOUR_APP_SECRET>");

//Define the bucket id and the dataset id
reference.setBucket(12);
reference.setDataset("my_dataset");

//Instead of a dataset, you also can use the auth token, when you want to use user specific data
reference.setAuthToken("<AUTH_TOKEN>");

As you can see in the example above, you have to create a reference. In this reference you also set your bucket id and dataset. If you want to use the personal dataset, which will be combined with the authentication service, then please use the setAuthToken instead of setDataset.

Inserting new data

Map<String, dynamic> data = {
    "column_a": "some data...",
    "column_b": 34,
    "another_column": true
};

reference.insert("fancy_container", data).then((response) {
    print(jsonDecode(response.body)["status"]);
    //If the status code is 200, then the data has been saved successfully.
    //If another status code is shown, then check the message parameter from the decoded response.body.
});

As the first parameter send the name of the container. The second parameter send a map data object as you can see above. As the keys there, define the column names.

Update existing data

You can also update existing data with a simple command.

Map<String, dynamic> data = {
    "column_a": "some newer data...",
    "another_column": false
};

reference.update("fancy_container", id, data).then((response) {
    print(jsonDecode(response.body)["status"]);
    //If the status code is 200, then the data has been saved successfully.
    //If another status code is shown, then check the message parameter from the decoded response.body.
});

Just also prepare the data in a map. When you call the function you send again as the first parameter the container name. The second parameter is now the item id. The item id can be retrieven when you call a get method. As the last parameter, you give the map object. Please note that you should also send data, which actually have not updated.

Delete data

Sometimes you also have to delete data. The process here is actually very similiar.

reference.delete("fancy_container", id).then((response) {
    print(jsonDecode(response.body)["status"]);
    //If the status code is 200, then the data has been saved successfully.
    //If another status code is shown, then check the message parameter from the decoded response.body.
});

The first parameter define the container name. The second and already last parameter is the row / item id.