Socket
Book a DemoInstallSign in
Socket

factory-mysql-fixtures

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

factory-mysql-fixtures

Factory to load fixtures on mysql database

1.1.0
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

factory-mysql-fixtures

Build Status

Factory to load fixtures on mysql database. Based on Factory Girl and Factory Lady.

Installation

Install via npm:

$ npm install factory-mysql-fixtures

Usage

Configuring Factory

var Factory = require('factory-mysql-fixtures');

var dbConf = {
  host: 'localhost',
  user: 'root',
  database: 'db-test',
  password: 'db-password', // optional
  timezone: 'utc',
  dbStructureFile: './build/structure.sql' // set your own script to reload initial data when calling clean method
};
  
Factory.config(dbConf);

Defining Factories

var _nameIndex = 0;
Factory.define('person', { 
  name: function(cb) { cb('Jack - ' + _nameIndex++ ); } // lazy attribute
  email: 'jack@mail.com' 
});

Factory.define('device', { 
  hash: 'hash1', 
  person_id: Factory.assoc('person', 'id') // simply Factory.assoc('person') for person object itself
});

Using Factories

Factory.create('person', { name: 'Fred', email: 'fred@mail.com' }, function(err, result) {
  // result is the saved person id
});

Factory.create('device', null, function(err, result) {
  // result is the saved device id
});

Clean Database

Factory.clean(function(err) {
  // data reloaded
});

License

Copyright (c) 2014 Max Claus Nunes. This software is licensed under the MIT License.

Keywords

factory

FAQs

Package last updated on 23 Jul 2015

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.