Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chaudum/crate-jsdk
A pure Javascript Development Kit for Crate for the browser.
https://github.com/chaudum/crate-jsdk
Last synced: about 22 hours ago
JSON representation
A pure Javascript Development Kit for Crate for the browser.
- Host: GitHub
- URL: https://github.com/chaudum/crate-jsdk
- Owner: chaudum
- License: apache-2.0
- Created: 2015-01-26T23:31:26.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-29T10:03:17.000Z (almost 10 years ago)
- Last Synced: 2023-03-26T15:48:37.512Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://crate.io
- Size: 207 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# crate-jsdk
Pure Javascript Development Kit for Crate## Installing
Install `crate-jsdk` via bower:
bower install https://github.com/chaudum/crate-jsdk.git
Load `crate.js` and its dependencies (only `reqwest`) in your html file:
```html
```
## Usage
The Crate client requires a single argument which is the host to connect to:
```js
var client = new Client('http://c1.example.com:4200');
```The client also supports multiple hosts as parameter:
```js
var client = new Client([
'http://c1.example.com:4200',
'http://c2.example.com:4200',
'http://c2.example.com:4200'
]);
```The `execute` method returns a [Javascript Promise](http://www.html5rocks.com/en/tutorials/es6/promises/):
```js
var promise = client.execute('select name from sys.cluster');
promise.then(function(response){
console.log(response.cols); // ['name']
console.log(response.rowcount) // 1
console.log(response.rows) // [['crate']]
console.log(response.toObjectArray()) // [{'name':'crate'}]
}).catch(function(response){
console.error(response.error.code);
console.error(response.error.message);
});
```### Cluster Health
The SDK also contains a `Cluster` JS class that can be used to determine
the health of tables and the cluster:```js
var cluster = new Cluster('http://c1.example.com:4200');
cluster.fetch().then(function(cluster){
console.log(cluster.id); // 9640b776-5128-4654-94c6-46fd1c6cf194
console.log(cluster.name); // jsdk
console.log(cluster.tables); // [{'full_table_name': '...', 'health_name': 'good', ...}, ...]
console.log(cluster.health); // {'code: 0, 'name': 'good'}
});
```## Development
```sh
python2.7 bootstrap.py
bin/buildout -N
bin/bower install
```To run tests:
```sh
bin/crate
```Then open file `tests/index.html` in the browser.