Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/varharrie/persiston
Simple persistent store with database-like API.
https://github.com/varharrie/persiston
database deno storage
Last synced: about 5 hours ago
JSON representation
Simple persistent store with database-like API.
- Host: GitHub
- URL: https://github.com/varharrie/persiston
- Owner: varHarrie
- License: mit
- Created: 2022-02-17T17:02:56.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-23T01:45:32.000Z (over 2 years ago)
- Last Synced: 2024-10-17T21:15:17.715Z (about 1 month ago)
- Topics: database, deno, storage
- Language: TypeScript
- Homepage: https://deno.land/x/persiston
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Persiston for Deno
Simple persistent store with database-like API.
## Usage
```javascript
const adapter = new FileAdapter('./data.json')
const store = new Persiston({ adapter })store.load()
.then(() => store.collection('users').insert({ name: 'foo' }))
.then(() => store.collection('users').findOne())
.then((user) => console.log(user)) // { name: 'foo' }
```With type declaration:
```typescript
interface User {
name: string
}class Store extends Persiston {
users = this.collection('users')
pets = this.collection('pets')
}const adapter = new FileAdapter('./data.json')
const store = new Store({ adapter })store.load()
.then(() => store.collection('users').insert({ name: 'foo' }))
.then(() => store.collection('users').findOne())
.then((user) => console.log(user)) // { name: 'foo' }
```## APIs
### Persiston
- `store.load(): Promise`
Loads data by adapter. It should be called before all collection operations.
- `store.save(): Promise`
Saves data by adapter. You probably won't call it by yourself.
- `store.collection(): Collection`
Gets a collection object.
### Collection
- `collection.find(query?: Query, fields?: string[]): Promise`
Finds items by query.
- `collection.findOne(query?: Query, fields?: string[]): Promise`
Finds an item by query.
- `collection.insert(items: T | T[]): Promise`
Saves given item or items.
- `collection.update(query: Query, changes: Partial): Promise`
Partially updates by query.
- `collection.updateOne(query: Query, changes: Partial): Promise`
Partially updates an item by query.
- `collection.remove(query?: Query): Promise`
Removes items by query.
- `collection.removeOne(query: Query): Promise`
Removes an item by query.