1.0.3 • Published 4 years ago

@validatecl/schema-loader v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@validatecl/schema-loader

Build Status GitHub GitHub last commit npm (scoped) npm

Schema loader for Mongoose connections.

Installation

npm i @validatecl/schema-loader

Usage

Use it to load your schemas into any Mongoose connection.

./configs/schemas.ts:

import { SchemasMap, SchemaLoaderOptions } from '@validatecl/schema-loader';

// You could move the schema map to another sub-module...
import profile from '../schemas/profile';
import user from '../schemas/user';

const schemas: SchemasMap = new Map();

schemas.set('profile', profile);
schemas.set('user', user);

const options: SchemaLoaderOptions = {
  replace: false,
  clone: true
};

export default {
  schemas,
  options
};

./components/schemas.ts:

import { createSchemaLoader, SchemaLoader } from '@validatecl/schema-loader';
import { Connection } from 'mongoose';

import { options, schemas } from '../configs/schemas';
import db from '../components/database';

const conn: Connection = db.connection('default');
const loader: SchemaLoader = createSchemaLoader(conn, options);

loader.loadAll(schemas);

export default loader;

Documentation

Please visit the documentation page for more info and options.

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago