Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #122 from doug-martin/master
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
doug-martin committed Jun 28, 2014
2 parents 88360de + 2b409b4 commit dcf0f18
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 433 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#0.7.0

* Fix for issue [#121](https://github.com/C2FO/patio/issues/121) added the table name to the error thrown.
* Merged [#120](https://github.com/C2FO/patio/pull/120) this allows tables registered with DB to be looked up properly.
* This will break any `getModel` call where a table with the same name is added twice.
* Added documentation about running tests.

#0.6.1

* Added details for logging if the err.detail exists.
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ If you want to use the patio executable for migrations

`npm install -g patio`

###Running Tests

To run the tests

```
make test
```

To run just the postgres tests

```
make test-pg
```

To run just the mysql tests

```
make test-mysql
```

###Why Use Patio?

Patio is different because it allows the developers to choose the level of abtraction they are comfortable with.
Expand Down
391 changes: 194 additions & 197 deletions docs-md/coverage.html

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions docs/History.html
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@



<h1>0.7.0</h1>
<ul>
<li>Fix for issue <a href="https://github.com/C2FO/patio/issues/121">#121</a> added the table name to the error thrown.</li>
<li>Merged <a href="https://github.com/C2FO/patio/pull/120">#120</a> this allows tables registered with DB to be looked up properly.<ul>
<li>This will break any <code>getModel</code> call where a table with the same name is added twice.</li>
</ul>
</li>
<li>Added documentation about running tests. </li>
</ul>
<h1>0.6.1</h1>
<ul>
<li>Added details for logging if the err.detail exists.</li>
Expand Down
391 changes: 194 additions & 197 deletions docs/coverage.html

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@ <h3>Installation</h3>
<p><code>npm install comb patio</code></p>
<p>If you want to use the patio executable for migrations</p>
<p><code>npm install -g patio</code></p>
<h3>Running Tests</h3>
<p>To run the tests </p>
<pre class='prettyprint linenums lang-js'><code>make test</code></pre>
<p>To run just the postgres tests</p>
<pre class='prettyprint linenums lang-js'><code>make test-pg</code></pre>
<p>To run just the mysql tests</p>
<pre class='prettyprint linenums lang-js'><code>make test-mysql</code></pre>
<h3>Why Use Patio?</h3>
<p>Patio is different because it allows the developers to choose the level of abtraction they are comfortable with. </p>
<p>If you want to use the <a href="http://c2fo.github.com/patio/models.html">ORM</a> functionality you can. If you don&#39;t you can just use the <a href="http://c2fo.github.com/patio/DDL.html">Database</a> and <a href="http://c2fo.github.com/patio/querying.html">Datasets</a> as a querying API, and if you need to you can <a href="http://c2fo.github.com/patio/patio_Database.html#run">write plain SQL</a></p>
Expand Down
50 changes: 23 additions & 27 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ var applyColumnTransformMethod = function (val, meth) {
return !isUndefinedOrNull(meth) ? isFunction(val[meth]) ? val[meth] : isFunction(comb[meth]) ? comb[meth](val) : val : val;
};

var checkAndTransformName = function (name) {
return isString(name) ? applyColumnTransformMethod(name, Model.camelize === true ? "camelize" : Model.underscore === true ? "underscore" : null) : name;
};

var Model = define([QueryPlugin, Middleware], {
instance: {
/**
Expand Down Expand Up @@ -328,7 +324,7 @@ var Model = define([QueryPlugin, Middleware], {
}
var raiseOnError = clazz.raiseOnTypecastError;
if (raiseOnError === true && isUndefinedOrNull(value) && colSchema.allowNull === false) {
throw new ModelError("null is not allowed for the " + column + " column.");
throw new ModelError("null is not allowed for the " + column + " column on model " + clazz.tableName);
}
try {
value = clazz.db.typecastValue(type, value);
Expand Down Expand Up @@ -628,10 +624,10 @@ var Model = define([QueryPlugin, Middleware], {
return when(supers.map(function (sup) {
return sup.sync();
})).chain(function () {
self.synced = true;
supers.forEach(self.inherits, self);
return self;
});
self.synced = true;
supers.forEach(self.inherits, self);
return self;
});
} else {
self.synced = true;
return self;
Expand Down Expand Up @@ -704,26 +700,26 @@ var Model = define([QueryPlugin, Middleware], {
var retVal = null, errored = false, self = this;
return this.sync().chain(function () {
if (self.useTransaction(opts)) {
return self.db.transaction(opts,function () {
return self.db.transaction(opts, function () {
return when(cb()).chain(function (val) {
retVal = val;
}, function (err) {
retVal = err;
errored = true;
});
}).chain(function () {
if (errored) {
throw retVal;
} else {
return retVal;
}
}, function (err) {
if (errored) {
throw retVal;
} else {
throw err;
}
});
if (errored) {
throw retVal;
} else {
return retVal;
}
}, function (err) {
if (errored) {
throw retVal;
} else {
throw err;
}
});
} else {
return when(cb());
}
Expand Down Expand Up @@ -1010,11 +1006,13 @@ function checkAndAddDBToTable(db, table) {
}
}

var allModels = [];
/**@ignore*/
exports.create = function (name, supers, modelOptions) {
if (!patio) {
(patio = require("./index"));
patio.on("disconnect", function () {
allModels.length = 0;
MODELS.clear();
});
}
Expand Down Expand Up @@ -1061,18 +1059,16 @@ exports.create = function (name, supers, modelOptions) {
}
}
});
allModels.push(model);
if (!(MODELS.get(db).contains(tableName))) {
MODELS.get(db).set(tableName, model);
}
return model;
};

exports.syncModels = function (cb) {
return asyncArray(MODELS.entrySet).map(function (entry) {
var value = entry.value;
return asyncArray(value.entrySet).map(function (m) {
return m.value.sync();
}, 1);
return asyncArray(allModels).forEach(function (model) {
return model.sync();
}, 1).classic(cb).promise();
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "patio",
"description": "Patio query engine and ORM",
"version": "0.6.1",
"version": "0.7.0",
"keywords": [
"ORM",
"object relation mapper",
Expand Down
10 changes: 3 additions & 7 deletions test/model.customAccessors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var it = require('it'),
comb = require("comb-proxy");


it.describe("A model with custom accessors",function (it) {
it.describe("A model with custom accessors", function (it) {

it.beforeAll(function () {
return helper.createSchemaAndSync();
Expand Down Expand Up @@ -38,10 +38,7 @@ it.describe("A model with custom accessors",function (it) {
}
}
});

return CustomSettersEmployee.sync().chain(function() {
return CustomGettersEmployee.sync();
});
return patio.syncModels();
});

it.beforeEach(function () {
Expand Down Expand Up @@ -91,5 +88,4 @@ it.describe("A model with custom accessors",function (it) {
return helper.dropModels();
});

});

});
14 changes: 10 additions & 4 deletions test/model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,16 @@ it.describe("patio.Model", function (it) {
assert.equal(m.firstname, "dougie");
});

it.should("throw an error when setting a non nullable column to null", function () {
var m = new Employee({otherVal: "otherVal", firstname: "dougie"}, true);
try {
m.street = null;
} catch (e) {
assert.equal(e.message, "Model error : null is not allowed for the street column on model employee");
}
});

it.afterAll(function () {
return helper.dropModels();
});


});

});

0 comments on commit dcf0f18

Please sign in to comment.