Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tspace-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tspace-mongodb

mongodb query builder object relational mapping

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

tspace-mongodb

NPM version NPM downloads

Query builder object relation mapping

Install

Install with npm:

npm install tspace-mongodb --save

Usage

DB


import { DB } from 'tspace-mongodb'
(async () => {
    await new DB().raw((connect,db) => {
        const result =  await db.collection('users').find().toArray()
        connect.close()
        return result
    }})
    await new DB().collection('users').whereIn('id',[1,2,3]).get()
    await new DB().collection('users').first()
    await new DB().find(1)
    
    await new DB()
        .create({
            name : 'name',
            username: 'users'
        }).save()

    await new DB()
        .whereUser(1)
        .update({
            name: 'users12345'
        }).save()

    await new DB()
        .where('id',1)
        .delete()

})()

Model for relationship support hasOne ,hasMany,belongsTo

// in file User setup relation 
import { Model } from 'tspace-mongodb'
import Role from '../Role'
import Project from '../Project'
import Role from '../Role'
    class User extends Model {
        constructor(){
            super()
            this.hasMany({name : 'projects', model: Project })   
            this.hasOne({name : 'project', model: Project}) 
            this.belongsTo({name : 'role', model: Role , localField : 'roleId' ,foreignField : '_id' })  
        }
    } 
    export default User
/**
 * Model
 * 
 * @Usage Model
*/
import User from '../User'
(async () => {
    await new User().with('car','phones').get()
})()

Method chaining

method chaining for query data

where(column , operator , value)   
whereIn(column , [])
whereNotIn(column , [])
whereNull(column)
whereNotNull(column)
whereBetween (column , [value1 , value2])
join ({from,localField,foreignField,as,isObject}) 
limit (limit)
latest (...column)
oldest (...column)
insert(objects)
create(objects)
update (objects)

/**
 * relation
 * 
 * @Relation setup name in model
*/
with(name1 , name2,...nameN)
/**
 * query statement
 * 
 *  @Exec statement
*/
get()
first()
find(id)
save() /*for statement insert or update */

Setup

.env connection to database

NODE_ENV = development // production
// development
MONGODB_HOST = localhost
MONGODB_PORT = 3306
MONGODB_DATABASE = database

// production
MONGODB_HOST_PROD = localhost
MONGODB_PORT_PROD = 3306
MONGODB_DATABASE_PROD = database

Keywords

FAQs

Package last updated on 08 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc