Skip to content

Commit

Permalink
MySQLTable: Deprecate tableName property in favour of new name pr…
Browse files Browse the repository at this point in the history
…operty
  • Loading branch information
nwoltman committed Dec 2, 2016
1 parent 677be44 commit 1916ddc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ A class that provides convenient methods for performing queries.

* [MySQLTable](#MySQLTable)
* _instance_
* [.tableName](#MySQLTable+tableName) : <code>string</code>
* ~~[.tableName](#MySQLTable+tableName) : <code>string</code>~~
* [.name](#MySQLTable+name) : <code>string</code>
* [.schema](#MySQLTable+schema) : <code>string</code>
* [.pool](#MySQLTable+pool) : <code>[PoolPlus](#PoolPlus)</code>
* [.select(columns, [sqlString], [values], cb)](#MySQLTable+select) ⇒ <code>void</code>
Expand All @@ -318,7 +319,17 @@ A class that provides convenient methods for performing queries.

<a name="MySQLTable+tableName"></a>

### mySQLTable.tableName : <code>string</code>
### ~~mySQLTable.tableName : <code>string</code>~~
***Deprecated***

The table's name (as passed to [`poolPlus.defineTable()`](#PoolPlus+defineTable)).


---

<a name="MySQLTable+name"></a>

### mySQLTable.name : <code>string</code>
The table's name (as passed to [`poolPlus.defineTable()`](#PoolPlus+defineTable)).


Expand Down
22 changes: 19 additions & 3 deletions lib/MySQLTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ const util = require('util');
* @see {@link https://github.com/mysqljs/mysql#performing-queries}
*/
class MySQLTable {
constructor(tableName, schema, pool) {
constructor(name, schema, pool) {
/**
* The table's name (as passed to {@link PoolPlus#defineTable|`poolPlus.defineTable()`}).
* @deprecated since version 0.4.0 and will be removed in version 0.5.0.
* @member {string} MySQLTable#tableName
* @constant {string}
*/
this.tableName = tableName;
/**
* The table's name (as passed to {@link PoolPlus#defineTable|`poolPlus.defineTable()`}).
* @constant {string}
*/
this.name = name;
/**
* The table's schema (as passed to {@link PoolPlus#defineTable|`poolPlus.defineTable()`}).
* @constant {string}
Expand All @@ -25,7 +31,7 @@ class MySQLTable {
*/
this.pool = pool;

this._escapedName = pool.escapeId(tableName);
this._escapedName = pool.escapeId(name);
}

/**
Expand Down Expand Up @@ -328,4 +334,14 @@ MySQLTable.prototype.replace = util.deprecate(
'Use `.delete()` then `.insert()` instead.'
);

Object.defineProperty(MySQLTable.prototype, 'tableName', {
get: util.deprecate(
function() {
return this.name;
},
'The `mySQLTable.tableName` property has been deprecated and will be removed in version 0.5.0. ' +
'Please use the `name` property instead.'
),
});

module.exports = MySQLTable;
2 changes: 1 addition & 1 deletion lib/TableDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ function sqlToSchema(sql) {
const tableOptions = createTableParts[3];

const schema = {
tableName,
name: tableName,
columns: generateColumnSchema(createDefinitions),
primaryKey: generatePrimaryKeySchema(createDefinitions),
uniqueKeys: generateUniqueKeysSchema(createDefinitions),
Expand Down
11 changes: 10 additions & 1 deletion test/unit/MySQLTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('MySQLTable', () => {
});


describe('#tableName', () => {
describe('#tableName', () => { // TODO: Remove after v0.4.0 is released

it('should be the name of the table', () => {
testTable.tableName.should.equal('mysql_table_test_table');
Expand All @@ -46,6 +46,15 @@ describe('MySQLTable', () => {
});


describe('#name', () => {

it('should be the name of the table', () => {
testTable.name.should.equal('mysql_table_test_table');
});

});


describe('#schema', () => {

it('should be the original table schema', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/unit/PoolPlus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ describe('PoolPlus', () => {
it('should return a MySQLTable instance', () => {
const table = pool.defineTable(TEST_TABLE_NAME, TEST_TABLE_SCHEMA);
table.should.be.an.instanceOf(MySQLTable);
table.tableName.should.equal(TEST_TABLE_NAME);
table.tableName.should.equal(TEST_TABLE_NAME); // TODO: Remove after v0.4.0 is released
table.name.should.equal(TEST_TABLE_NAME);
table.schema.should.equal(TEST_TABLE_SCHEMA);
});

Expand Down

0 comments on commit 1916ddc

Please sign in to comment.