hexabase 0.8.4 copy "hexabase: ^0.8.4" to clipboard
hexabase: ^0.8.4 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;

Authentication #

Log in

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

Save session to localStorage, NSUserDefaults or SharedPreferences

// Save to local
client.persistence = Hexabase.persistenceLocal;
await client.login(keys['email'], keys['password']);

And next time, you should check login status like below.

if (await client.isLogin()) {
	// Login
} else {
	// Not login, or session is invalid.
}

Log out

var user = await client.getCurrentUser();
await user.logout();

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();

Group #

Get groups

var groups = await client.groups();

Find a group

var group = await client.group(id: '999999');

Create group

var group = await client.group();
group.name = 'Test group';
group.parent = groups[0];
group.displayId = 'test_group';
await group.save();

Update group

group.name = 'New group';
await group.save();

Delete group

Currently, this method is not working.

await group.delete();

Datastore #

Create datastore

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

Get datastore

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

Update datastore

var datastore = await project.datastore();
datastore.name('ja', 'テストデータストア').name('en', 'Test Datastore');
datastore.displayId = 'TestDatastore';
datastore.ignoreSaveTemplate = true;
await datastore.save();

Delete datastore

var datastore = await project.datastore();
await datastore.delete();

Datastore Item #

Search datastore items

var query = datastore.query);
query.equalTo('name', 'value');
var items = await datastore.items(query);
var response = await datastore.search(HBSearchType.history, "comment");
print(response.count); // Items count
print(response.items); // Items

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, logging, shared_preferences, signalr_netcore, tuple, uri

More

Packages that depend on hexabase