Socket
Socket
Sign inDemoInstall

easy-fixture

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    easy-fixture

This module will help you to manage you fixtures


Version published
Weekly downloads
10
Maintainers
1
Created
Weekly downloads
 

Readme

Source

easy-fixture

Motivation

If you have database with only few simple tables/collections things are simple. You can easiliy manage your fixture files. But trouble starts if you have complex tables/collections in database, and also relationships between them. In that case it is not easy to write fixture files, and also it is time wasting task.

With this module you can use current database state -> data added from your UI or on some other way. Idea is to have fixture manager which will freeze your current database state and save it into some local file. After that you will be able to load fixtures from that file into your database.

To make things easier, for each fixture manager there should be grunt/gulp task which makes this task even easier.

Available managers:

  • easy-mongo-fixture

Available Grunt tasks:

Making custom fixture manager

All you have to do is to extend Base object of easy-fixture.

Example
Base = require('easy-fixture').Base;

function CustomFixtureManager(opts) {
  Base.call(this);

  // your init logic here
}

util.inherits(CustomFixtureManager, Base);

/*
 * THIS METHOD SHOULD RETURN PROMISE
 */
CustomFixtureManager.prototype._load = function () {
  // implementation of method for loading data from local file, 
  // and saving it into corresponing database destination
};

/*
 * THIS METHOD SHOULD RETURN PROMISE
 */
CustomFixtureManager.prototype._save = function () {
  // implementation of method for collectiong data from database source, 
  // and saving it into local file(s).
};

After you create your CustomFixtureManager, you can use it on following way with easy-fixture:

var fixture = require('easy-fixture');

var fixtureManager = new CustomFixtureManager();

// you can use multiple fixture managers. It will append each manager to array
fixture.use(fixtureManager);

// save method will run _save action on each fixture manager
fixture.save().then(function () {
  console.log('saved');
});

// load method will run _load action on each fixture manager
fixture.load().then(function () {
  console.log('loaded');
});

License

MIT

Keywords

FAQs

Last updated on 26 Apr 2014

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