hexabase 0.5.6 copy "hexabase: ^0.5.6" to clipboard
hexabase: ^0.5.6 copied to clipboard

Dart and Flutter SDK for Hexabase

Hexabase SDK for Dart and Flutter #

Usage #

Import #

import 'package:hexabase/hexabase.dart';

Initializing #

Hexabase();

After initialized the client, you can take client object anytime.

var client = Hexabase.instance;

Log in #

await client.auth.login('you@example.com', 'your_secure_password');

Workspace #

Get all workspaces

var workspaces = await client.workspace.all();
// workspaces[0].id
// workspaces[0].name

Get workspace

var workspace = client.workspace(id: 'WORKSPACE_ID');

Project #

Get all projects

var projects = await workspace.projects();
print(projects[0].id);
print(projects[0].datastores[0].id);

Get project

var project = client.project(id: 'PROJECT_ID');

Create project

var project = client.project();
project.name('ja', 'テストアプリ').name('en', 'Test App');
await project.save();

Update project

var project = client.project(id: 'PROJECT_ID');
project.name('en', 'Test app v2');
await project.save();

Delete project

await project.delete();

Datastore #

Get datastore

var project = client.project(id: 'PROJECT_ID');
var datastore = project.datastore(id: 'DATASTORE_ID');

Datastore Item #

Search datastore items

var query.= datastore.query.);
query.equalTo('name', 'value');
var items = await datastore.items(query.;

Create new item

var item = datastore.item();
item.set('name', 'value').set('price', 100);
await item.save();

Update item

item.set('price', 110).set('salesDate', DateTime.now());
await item.save();

Update item status

item
	.action('startReservation') // Action ID or Action Id or Action name (English) or Action name (Japanese)
	.set('salesDate', DateTime.now()); // You can also update other fields
await item.save();

Upload file

var filePath = './test/test.png';
var file = HexabaseFile(
		name: basename(filePath), contentType: lookupMimeType(filePath));
file.data = File(filePath).readAsBytesSync();
item.set('picture', file);
await item.save();

Upload files

var filePaths = ['./test/test.png', './test/test2.png'];
for (var filePath in filePaths) {
	var file = HexabaseFile(
			name: basename(filePath), contentType: lookupMimeType(filePath));
	file.data = File(filePath).readAsBytesSync();
	item.add('picture', file);
}
await item.save();

Download file

It returns multiple everytime. data is Unit8List;

var pictures = item.get('picture') as List<HexabaseFile>;
var data = await pictures[0].download();

Delete file

await pictures[0].delete();

Delete item

await item.delete();

Get field data

item.get('name');
item.getAsString('name');
item.getAsInt('name');
item.getAsDouble('name');
item.getAsDateTime('name');
item.getAsBool('name');

// w/ default value
item.getAsString('name', defaultValue: "Hello");
item.getAsInt('name', defaultValue: 100);
item.getAsDouble('name', defaultValue: 3.14156);
item.getAsDateTime('name', defaultValue: DateTime.now());
item.getAsBool('name', defaultValue: true);

Search conditions #

Equal to

var query.= datastore.query();
query.equalTo('name', 'value');

Not equal to

query.notEqualTo("name", "value");

Greater than ">"

Only support int and DateTime.

query.greaterThan("price", 100);

Greater than or equal ">="

Only support int and DateTime.

query.greaterThanOrEqualTo("price", 100);

Less than "<"

Only support int and DateTime.

query.lessThan("price", 100);

Less than or equal "<="

Only support int and DateTime.

query.lessThanOrEqualTo("price", 100);

In

// name == "Apple" or name == "Orange"
query.inArray("name", ["Apple", "Orange"]);

Not in

// name != "Apple" && name != "Orange"
query.notInArray("name", ["Apple", "Orange"]);

License #

MIT License

2
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Dart and Flutter SDK for Hexabase

Homepage

License

unknown (LICENSE)

Dependencies

collection, dio, eventsource, graphql, http, http_parser, jwt_decode, tuple, uri

More

Packages that depend on hexabase