|
1 | 1 | # @dataparty/api |
2 | 2 | [](http://github.com/badges/stability-badges)[](https://github.com/datapartyjs/dataparty-api/blob/master/LICENSE) |
3 | 3 |
|
4 | | -@dataparty/api is an ad-hoc cloud solution for the Web3.0 generation. |
| 4 | +ad-hoc cloud for the Web3.0 generation |
5 | 5 |
|
6 | 6 | * Documentation - [datapartyjs.github.io/dataparty-api](https://datapartyjs.github.io/dataparty-api) |
7 | 7 | * NPM - [npmjs.com/package/@dataparty/api](https://www.npmjs.com/package/@dataparty/api) |
8 | 8 | * Code - [github.com/datapartyjs/dataparty-api](https://github.com/datapartyjs/dataparty-api) |
9 | 9 | * Support - [ko-fi/dataparty](https://ko-fi.com/dataparty) |
10 | 10 |
|
11 | | -# Goals |
| 11 | +## Goals |
12 | 12 |
|
13 | | -The primary goal of @dataparty/api is to push |
| 13 | +The primary goal of `@dataparty/api` is to enable secure microservices development across all architectual domains with a single code base. This covers traditional clouds, peer-to-peer apps(with or without cloud backing), and hybrid clouds. |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## Roadmap |
| 18 | + |
| 19 | +Currently this project is considered `Experimental`, throughout 2023 we'll be working towards our first stable releases. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +## Example |
| 26 | + |
| 27 | +``` |
| 28 | +
|
| 29 | +const Dataparty = require('@dataparty/api') |
| 30 | +
|
| 31 | +
|
| 32 | +async function getUser(name) { |
| 33 | + return (await local.find() |
| 34 | + .type('user') |
| 35 | + .where('name').equals(name) |
| 36 | + .exec())[0] |
| 37 | +} |
| 38 | +
|
| 39 | +
|
| 40 | +async function main(){ |
| 41 | + const dbPath = (await fs.mkdtemp('/tmp/loki-party')) + '/loki.db' |
| 42 | +
|
| 43 | + debug('db location', dbPath) |
| 44 | +
|
| 45 | + local = new Dataparty.LokiParty({ |
| 46 | + path: dbPath, |
| 47 | + model: MyServiceModel, |
| 48 | + config: new Dataparty.Config.MemoryConfig() |
| 49 | + }) |
| 50 | +
|
| 51 | +
|
| 52 | + await local.start() |
| 53 | +
|
| 54 | + let user = await getUser('tester') |
| 55 | +
|
| 56 | + |
| 57 | + if(!user){ |
| 58 | + debug('creating document') |
| 59 | + user = await local.createDocument('user', {name: 'tester', created: (new Date()).toISOString() }) |
| 60 | + } |
| 61 | + else{ |
| 62 | + debug('loaded document') |
| 63 | + } |
| 64 | +
|
| 65 | + console.log(user.data) |
| 66 | +
|
| 67 | +
|
| 68 | + user.data.name = 'renamed-tester' |
| 69 | +
|
| 70 | + await user.save() |
| 71 | +
|
| 72 | + console.log(user.data) |
| 73 | +
|
| 74 | + let userFind = await getUser('renamed-tester') |
| 75 | +
|
| 76 | + console.log(userFind) |
| 77 | +
|
| 78 | +
|
| 79 | + console.log(dbPath) |
| 80 | +
|
| 81 | +
|
| 82 | + await user.remove() |
| 83 | +
|
| 84 | + console.log(await getUser('renamed-tester')) |
| 85 | +
|
| 86 | +} |
| 87 | +``` |
0 commit comments