Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maxcnunes/factory-mysql-fixtures
Factory to load fixtures on mysql database.
https://github.com/maxcnunes/factory-mysql-fixtures
Last synced: about 1 month ago
JSON representation
Factory to load fixtures on mysql database.
- Host: GitHub
- URL: https://github.com/maxcnunes/factory-mysql-fixtures
- Owner: maxcnunes
- License: mit
- Created: 2014-03-15T23:42:37.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-23T02:28:52.000Z (over 9 years ago)
- Last Synced: 2024-10-18T07:23:20.547Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 198 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
factory-mysql-fixtures
======================[![Build Status](https://travis-ci.org/maxcnunes/factory-mysql-fixtures.png?branch=master)](https://travis-ci.org/maxcnunes/factory-mysql-fixtures)
Factory to load fixtures on mysql database. Based on [Factory Girl](https://github.com/thoughtbot/factory_girl) and [Factory Lady](https://github.com/petejkim/factory-lady).
## Installation
Install via npm:
$ npm install factory-mysql-fixtures
## Usage
### Configuring Factory
```javascript
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
```javascript
var _nameIndex = 0;
Factory.define('person', {
name: function(cb) { cb('Jack - ' + _nameIndex++ ); } // lazy attribute
email: '[email protected]'
});Factory.define('device', {
hash: 'hash1',
person_id: Factory.assoc('person', 'id') // simply Factory.assoc('person') for person object itself
});```
### Using Factories
```javascript
Factory.create('person', { name: 'Fred', email: '[email protected]' }, function(err, result) {
// result is the saved person id
});Factory.create('device', null, function(err, result) {
// result is the saved device id
});```
### Clean Database
```javascript
Factory.clean(function(err) {
// data reloaded
});```
## License
Copyright (c) 2014 Max Claus Nunes. This software is licensed under the [MIT License](http://raw.github.com/maxcnunes/factory-mysql-fixtures/master/LICENSE).