0.1.3 • Published 3 years ago

type-dexie v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

type-dexie

type-dexie is a class oriented schema building tool for dexie.js. What that means is that you will not be writing schema strings while you are using dexie.js. Instead, you will be decorating your models and type-dexie will create the stores! Cool right? At least, I thought that it would be cool and here we are :)

Usage

  • First, simply define your models;
class User {
  id: number;
  username: string;
}
  • Then, decorate them appropriately;
class User {
  @Column()
  @Primary()
  id: number;

  @Column()
  username: string;
}
  • After that, type-dexie is ready to create a schema for you;
const schema = compileSchema(User /* (1) */);

console.log(schema.users); // ++id, username

1. Other entities if you have any

Pseudo-relations

As you may know, I am calling it pseudo because IndexedDB does not support relations. Even so, type-dexie will parse the columns that you have typed and specify that it is a relation.

Example!

@Entity()
class User {
  @Column()
  @Primary()
  id: number;

  @Column()
  username: string;

  @Column(() => [Photo])
  photo: Photo[];
}

@Entity()
class Photo {
  @Column()
  @Primary()
  id: number;

  @Column()
  url: string;

  @Column()
  tags: string[];
}

const schema = compileSchema(User);

console.log(schema.users); // ++id, username
console.log(schema.photos); // ++id, url, tags, user

Storing relation where it is defined

@Entity()
class User {
  @Column()
  @Primary()
  id: number;

  @Column()
  username: string;

  @Column()
  @JoinColumn()
  profile: Profile;
}

@Entity()
class Profile {
  @Column()
  @Primary()
  id: number;

  @Column()
  biography: string;
}

const schema = compileSchema(User);

console.log(schema.users); // ++id, username, profile
console.log(schema.photos); // ++id, url, tags
0.1.0

3 years ago

0.1.2

3 years ago

0.0.3

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.0.1

3 years ago