Saving Single Object¶
Method¶
Future<Map> Backendless.data.of("TABLE-NAME").save(Map entity);
Future<E> Backendless.data.withClass<E>().save(E entity);
where:
Argument | Description |
---|---|
TABLE-NAME |
Name of the table where the object represented by Map will be saved. |
E |
Dart class of the data object to save. |
entity |
Dart object to persist, must be of type E or Map (depending on the method used). |
Return Value¶
The saved object of type E or Map.
Example¶
void saveNewContact() {
Map contact = {
"name": "Jack Daniels",
"age": 147,
"phone": "777-777-777",
"title": "Favorites",
};
Backendless.data.of( "Contact" ).save(contact).then((response) {
// new Contact instance has been saved
});
}
import 'package:backendless_sdk/backendless_sdk.dart';
@reflector
class Contact {
String objectId;
String name;
int age;
String phone;
String title;
}
void saveNewContact() {
Contact contact = Contact()
..name = "Jack Daniels"
..age = 147
..phone = "777-777-777"
..title = "Favorites";
Backendless.data.withClass<Contact>().save(contact).then((response) {
// new Contact instance has been saved
});
}
Codeless Reference¶
where:
Argument | Description |
---|---|
table name |
Name of the data table where a new record must be saved. |
object |
An object to save in the database. Object properties must match the names of the table columns. The object must not have the objectId property. |
return result |
Optional parameter. When this box is checked, the operation returns the saved object with the objectId property. |
Returns the saved object with the objectId
property assigned by Backendless
Consider the following structure of the data table called employees
:
For demonstration purposes, the data table presented above has three custom columns: name
, position
, and phoneNumber
. The objectId
is a system column that contains unique identifiers of the records in the table. When a new record is saved to the table, the system assigns a unique objectId
to it. The objectid
is used in various operations as an access point to a specific record.
The example below saves a new object to the employees
data table:
The result of this operation will look as shown below after the Codeless logic runs:
The operation described above has returned the newly saved object: