npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fractalerp/active-record-js

v1.0.16

Published

Responsible for representing business data

Downloads

26

Readme

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;

|Method|Description| |------------------|-----------| |find|returns list of data objects| |findOne|returns one data item| |create|save item to the data store| |update|updates the record in the store| |delete|delete 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

|Method|Description| |------------------|-----------| |aggregate|peform aggregate action based on a pipeline| |index|create an index in the document store|

This only applies to Relational databases

|Method|Description| |------------------|-----------| |query|create a raw SQL to send to database| |beginTransaction|start a transaction| |commitTransaction|persist a transaction| |rollbackTransaction|rollback 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| |------------------|-----------| |start|Build the project and monitor source and config for changes and rebuild. Start the dev server| |watch|Build the project and monitor source and config for changes and rebuild.| |emit|Output javascript code| |test|Runs lint, build, unit tests with mocha and generates a coverage report| |test:dev|Runs mocha and watches for changes to re-run tests; does not generate coverage reports.| |test:unit|Runs unit tests with mocha and generates a coverage report.| |build:prod|Build app optimized for production| |build:dev|Build app optimized for debugging.| |lint|Lint all .js files.| |lint:fix|Lint and fix all .ts files.|