4.0.1 • Published 1 year ago

@stenodb/browser v4.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@stenodb/browser npm.io

✍ Easy to use local JSON database for LocalStorage and SessionStorage.

Install

npm install @stenodb/browser
yarn add @stenodb/browser
pnpm add @stenodb/browser

Usage

// entities.ts
import { Type } from 'class-transformer'

export class Users {
  @Type(() => User)
  users: User[]

  constructor(...users: User[]) {
    this.users = users
  }
}

export class User {
  username: string

  @Type(() => Post)
  posts: Post[]

  constructor(username: string, ...posts: Post[]) {
    this.username = username
    this.posts = posts
  }

  addPost(post: Post) {
    this.posts.push(post)
  }
}

export class Post {
  title: string

  constructor(text: string) {
    this.title = title
  }
}

// index.ts
import 'reflect-metadata'
import { LocalStorage, BrowserProvider } from '@stenodb/browser'
import { Users, User, Post } from './entities.js'

const initialData = new Users(new User('John Doe'))
const adapter = new LocalStorage('users', Users, initialData)
const provider = new BrowserProvider()
const db = provider.create(adapter)

db.read()
db.data?.users[0]?.addPost(new Post('Lorem ipsum'))
db.write()

Credits

  • steno - Specialized fast async file writer.
  • class-transformer - Decorator-based transformation, serialization, and deserialization between objects and classes.
  • class-validator - Decorator-based property validation for classes.

License

MIT - crashmax

4.0.1

1 year ago

3.4.0

1 year ago

3.3.1

1 year ago

3.4.1

1 year ago

3.3.2

1 year ago

4.0.0

1 year ago

3.3.0

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago