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

@fractalerp/active-record-js

Package Overview
Dependencies
Maintainers
0
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fractalerp/active-record-js

Responsible for representing business data

  • 1.0.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by420%
Maintainers
0
Weekly downloads
 
Created
Source

Build Status Code Climate Dependency Status Dev Dependency Status Known Vulnerabilities Node 11 Npm 6 Webpack 5 codecov Coverage Status contributions welcome PRs Welcome code style: Tslint Latest FOSSA Status Apache License, Version 2.0

npm

ACTIVE RECORD JS

A library responsible for representing business data.

This library follows the Active Record Pattern by building a wrapper on top of popular orm such as Mongoose and Sequelize to support all kinds of databases

⚙️ How to use the package in project

  1. You should create the following environment variables in your node project.
RDBMS_DATABASE_URI="mysql://DATBASE_USER:DATABASE_PASSWORD@DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
NOSQL_DATABASE_URI="mongodb://DATABASE_HOST:DATABASE_PORT/DATABASE_DB"
NOSQL_DATABASE_ADAPTER="mongodb"
  1. Once the variables have been set. You should create a model base on the active record SchemaProperty. See example below
import { ActiveRecord } from "@fractalerp/active-record-js"

export interface ITaskModelDocument {
  name: string;
  description: string;
}

const TaskModelSchema = {
  name: {
    type: String,
    required: true,
    unique: true
  },
  description: {
    type: String,
    default: null
  }
};

export const TaskModel = new ActiveRecord<ITaskModelDocument>("Task", TaskModelSchema);

  1. Then use its methods to perform data management. The following methods are supported;
MethodDescription
findreturns list of data objects
findOnereturns one data item
createsave item to the data store
updateupdates the record in the store
deletedelete item from the data store

Since we support all kinds of databases. The following are the respective methods of the two kinds of databases.

This only applies to NOSQL databases

MethodDescription
aggregatepeform aggregate action based on a pipeline
indexcreate an index in the document store

This only applies to Relational databases

MethodDescription
querycreate a raw SQL to send to database
beginTransactionstart a transaction
commitTransactionpersist a transaction
rollbackTransactionrollback a transaction

Other than that, all the other ORM respective methods for Sequelize and Mongoose are supported by default.

  1. Finally you can use the model to peform data action. See example.
// create task
const task = await TaskModel.create({
    name: 'Use fractalerp active record js',
    description: 'Change all models'
});

// Find one task
const task = await TaskModel.findOne({ id: 'cbdabs-29232323-msasd'});
  1. You can also use the underlying ORM model and instance methods
// create task
const filter = { };
const countTasks = await TaskModel.model.countDocuments(filter);

🫶 Projects using this package

See the projects using this package in action.

🪲 Issues, suggestions and feature requests

We are actively maintaining this boilerplate, please report any issues or suggestion for improvement at https://github.com/fractalerp/active-record-js/issues

👩‍💻 Development and contribution

Prerequisite: Install git, node package manager, webpack CLI, grunt CLI

To contribute, fork and clone.

> git clone https://github.com/fractalerp/active-record-js.git

The code is in typescript. Use a typescript IDE of your choice, like Visual Studio Code or WebStorm.

To set up the development environment, run:

> npm install

To automatically compile, bundle and push code changes to the running test project, run:

> npm start

To run the project unit tests with code coverage, results can be found at dist/testresults/coverage/index.html, run:

> npm run test:unit

Run the unit test continuously during development:

> npm run test:dev

Scripts

While developing, you will probably rely mostly on npm start; however, there are additional scripts at your disposal:

npm run <script>Description
startBuild the project and monitor source and config for changes and rebuild. Start the dev server
watchBuild the project and monitor source and config for changes and rebuild.
emitOutput javascript code
testRuns lint, build, unit tests with mocha and generates a coverage report
test:devRuns mocha and watches for changes to re-run tests; does not generate coverage reports.
test:unitRuns unit tests with mocha and generates a coverage report.
build:prodBuild app optimized for production
build:devBuild app optimized for debugging.
lintLint all .js files.
lint:fixLint and fix all .ts files.

Keywords

FAQs

Package last updated on 11 Aug 2024

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