@interep/db v0.4.0
The @interep/db package is an internal package that contains utility functions, models and methods used in the system to interact with persistent data, and its purpose is to make Interep more database-agnostic. Interep currently uses MongoDB and Mongoose.
🛠 Install
npm or yarn
Install the @interep/db package with npm:
npm i @interep/db --saveor yarn:
yarn add @interep/db📜 Usage
# connect(mongoUrl: string, errorListener?: (...args: any[]) => void): Promise<boolean>
import { connect } from "@interep/db"
const { MONGO_URL } = process.env
await connect(MONGO_URL)
// or await connect(MONGO_URL, (error) => console.error(error))# disconnect(): Promise<boolean>
import { disconnect } from "@interep/db"
await disconnect()# clear(): Promise<boolean>
import { clear } from "@interep/db"
await clear() // Delete all the db entries.# drop(): Promise<boolean>
import { drop } from "@interep/db"
await drop() // Drop the db.# getState(): number
import { getState } from "@interep/db"
const state = getState()
/*
Connection ready state:
- 0 = disconnected
- 1 = connected
- 2 = connecting
- 3 = disconnecting
*/You can find the model of each entity on src/<entityName>/<EntityName.model.ts>. Each model has predefined functions and some custom static functions defined on src/<entityName>/<EntityName>.statics.ts. The @interep/db package also exports types and models of each entity.