Socket
Socket
Sign inDemoInstall

objectionjs-repository

Package Overview
Dependencies
2
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    objectionjs-repository

ObjectionJS Repository is repository pattern implementation on top of KnexJS and ObjectionJS


Version published
Weekly downloads
11
decreased by-31.25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

ObjectionJS Repository

ObjectionJS Repository is repository pattern implementation on top of KnexJS and ObjectionJS

Latest Stable Version License NPM Downloads NPM Downloads

Content

  1. Installation
  2. Usage
  3. API
    1. getOne
    2. getAll
    3. create
    4. createMany
    5. update
    6. delete
  4. Options
  5. Tests
  6. Support

Installation

$ npm i objectionjs-repository

Usage

// Define Interface
export interface IUser {
  id: number;
  age: number;
  name: string;
}

// Define Model
export default class User extends Model {
  static get tableName() {
    return TABLES.USER;
  }
}

// Define Repository
import { BaseRepository } from 'objectionjs-repository';

export class UserRepository extends BaseRepository<IUser> {
  constructor(knexInstance: Knex) {
    super(User, knexInstance);
  }
}

then you can use defined repository

   const userRepo = new UserRepository(knexInstance);
   const user = await userRepo.getOne({ age: 25 })

API

getOne(conditions, [options])

conditions is object contains any column in this table.
options is IFindingOptions.
return selected row or undefined

getAll(conditions, [options])

conditions is object contains any column in this table.
options is IFindingOptions.
return selected rows or empty array.

create(data, [options])

data to be inserted.
options is ICreationOptions.

createMany(data, [options])

array to be inserted.
options is ICreationOptions.

update(conditions, data, [options])

conditions is object contains any column in this table.
data to be updated.
options is IUpdatingOptions.

delete(conditions, [options])

conditions is object contains any column in this table.
options is IDeletionOptions.

Options

IFindingOptions
IFindingOptions {
  // select specific columns
  select?: string[];
  // database Transaction
  trx?: Knex.Transaction;
  // lock selected rows or not
  forUpdate?: boolean;
  // select where column not in array
  whereNotIn?: {
    field: string;
    values: any;
  }[];
  // select where column in array
  whereIn?: {
    field: string;
    values: any;
  }[];
  // select where columns is null
  whereNull?: string[];
  // select where columns is not null
  whereNotNull?: string[];
}
ICreationOptions
ICreationOptions {
  // database Transaction
  trx?: Knex.Transaction;
}
IUpdatingOptions
IUpdatingOptions {
  // database Transaction
  trx?: Knex.Transaction;
  // select where column not in array
  whereNotIn?: {
    field: string;
    values: any;
  }[];
  // select where column in array
  whereIn?: {
    field: string;
    values: any;
  }[];

  // select where columns is null
  whereNull?: string[];
  // select where columns is not null
  whereNotNull?: string[];
}
IDeletionOptions
IDeletionOptions {
  // database Transaction
  trx?: Knex.Transaction;
  // select where column not in array
  whereNotIn?: {
    field: string;
    values: any;
  }[];
  // select where column in array
  whereIn?: {
    field: string;
    values: any;
  }[];
  // select where columns is null
  whereNull?: string[];
  // select where columns is not null
  whereNotNull?: string[];
}

Tests

To run the test suite, first install the dependencies and rename .env.sample to .env and set connection url for postgres database in .env then run npm test:

$ npm install
$ npm test

Support

Feel free to open issues on github.

Keywords

FAQs

Last updated on 07 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc