Skip to content

gerard2perez/vault-orm

Repository files navigation

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();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published