1.0.4 • Published 7 years ago

jinwookie-mongodb-crud v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

jinwookie-crud-router

Package to create CRUD routes on express. Also, create a CRUD data layer, and execute queries in mongodb.

Installation

npm install jinwookie-crud-router

Usage

executeQuery

executes queries in the function passed in. Automatically will open connection before queries are executed, and then close the connection after queries executed.

function executeQuery(func)

Parameters

func: (db) => Promise<result>

db: mongodb db object

Crud

CRUD data layer for mongodb

function crud(options) => {
  insert,
  select,
  selectOne,
  updateOne,
  deleteOne,
}

options

tableName: Name of mongodb table

fields: Object model

[
  {
    column: string
    type: 'string' | 'number' | 'boolean' | 'ObjectId' | 'any'
    key: boolean
  }
  ...
]

queries?: parameters used to query table

[
  {
    column: string
    type: 'string' | 'number' | 'boolean' | 'ObjectId' | 'any'
  }
]

selectFunc?: additional mongodb pipeline for find

(pipeline) => <additional pipeline>

selectOneFunc?: additional mongodb pipeline for retrieving single record

(pipeline) => <additional pipeline>

CrudRouter

Creates an express router to handle CRUD methods

function crudRouter(options) => Router

options

crud: Crud data object

model?: function to set model for POST/PUT

(req: Request) => object

defaults to req.body

select?: function to return select object for GET

(req: Request) => object

defaults to { ...req.params, ...req.query }

Environment Variables

DB_CONN=mongodb+srv://{username}:<PASSWORD>@{cluster}?retryWrites=true
DB_NAME={dbname}
DB_PASSWORD={dbpassword}
1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago