@gerard2p/vault-orm
TypeScript icon, indicating that this package has built-in type declarations

0.4.6 • Public • Published

Vault ORM

FOSSA Status

Build StatusDependency StatusPRs Welcome

Code Climate Test Coverage Issue Count

semantic-releaseCommitizen friendlyTypeScript

Installation

npm install @gerard2p/vault-orm

About

Vault ORM is part of the Kane framework and evolution of Koaton. but rigth now it's only for private usage; but you can use vault-orm

Models

This sample shows how to create a model

// database/posts.ts
import { Model } from '@gerard2p/vault-orm/adapters/mongo';
import { Related, List, Property, HasMany, HasOne, BelongsTo } from '@gerard2p/vault-orm/types';
import { User } from './user';
import { Comment } from './comment';
export class Post extends Model {
	@Property title:string
	@Property description:string
	@BelongsTo(o=>User, 'myOwnerKey') user:Related<User>
	@HasMany(o=>Comment, 'commentRelationKey') comments: List<Comment>
}

Vault ORM will auto detect the types from typescript and aditionaly it has some tpes to manage relations.

Database

import { Collection, VaultORM, collection, RelationMode } from '@gerard2p/vault-orm/adapters/mongo';
import { Rigth } from './rigth';
import { Rol } from './rol';
import { User } from './user';
import { Post } from './post';
import { Comment } from './comment';

VaultORM.RelationsMode = RelationMode.id;
class TestContext extends VaultORM {
	@collection(Rigth) rigths: Collection<Rigth>
	@collection(Rol) rols: Collection<Rol>
	@collection(User) users: Collection<User>
	@collection(Post) posts: Collection<Post>
	@collection(Comment) comments: Collection<Comment>
}
const Context =  new TestContext({
    database: 'test_vault_orm',
    port: 27017,
    host: 'localhost'
}, {
    poolSize: 2
});
export { Context, Context as TestContext };

The export at the end of the line is required when using Kaen Framework.

You can wait for the databse to initialize using the ready() promise that is available await TestContext.ready();

/@gerard2p/vault-orm/

    Package Sidebar

    Install

    npm i @gerard2p/vault-orm

    Weekly Downloads

    1

    Version

    0.4.6

    License

    MIT

    Unpacked Size

    111 kB

    Total Files

    46

    Last publish

    Collaborators

    • gerard2p