Navigation Menu

Skip to content

Commit

Permalink
alter table => reference table
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Aug 3, 2012
1 parent 171618b commit 5bfd526
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
40 changes: 20 additions & 20 deletions lib/database/index-field.js
Expand Up @@ -65,12 +65,12 @@ IndexField.prototype = {
this._indexColumnName = this.domain.tableName + '_' + this.columnName;
return this._indexColumnName;
},
get alterTableName() {
if (!this._alterTableName)
this._alterTableName = this.domain.tableName + '_' + this.columnName;
return this._alterTableName;
get referenceTableName() {
if (!this._referenceTableName)
this._referenceTableName = this.domain.tableName + '_' + this.columnName;
return this._referenceTableName;
},
get alterTableKeyType() {
get referenceTableKeyType() {
var type = this.type;
switch (type) {
case 'uint':
Expand All @@ -79,7 +79,7 @@ IndexField.prototype = {
return nroonga.ShortText;
default:
throw new Error('Unsupported index field type ' + type +
' for alter table');
' for reference table');
}
},
fieldTypeToColumnType: function(fieldType) {
Expand All @@ -89,7 +89,7 @@ IndexField.prototype = {
case 'uint':
return nroonga.UInt32;
case 'literal':
return this.alterTableName;
return this.referenceTableName;
default:
throw new Error('Unsupported index field type ' + fieldType);
}
Expand All @@ -100,7 +100,7 @@ IndexField.prototype = {
return 'text';
case nroonga.UInt32:
return 'uint';
case this.alterTableName:
case this.referenceTableName:
return 'literal';
default:
throw new Error('Unsupported column type ' + columnType);
Expand Down Expand Up @@ -130,7 +130,7 @@ IndexField.prototype = {
} else if (column.type == 'fix') {
if (column.range == nroonga.UInt32)
return this._type = 'uint';
else if (column.range == this.alterTableName)
else if (column.range == this.referenceTableName)
return this._type = 'literal';
}

Expand Down Expand Up @@ -161,18 +161,18 @@ IndexField.prototype = {
},

createSync: function() {
var alterTableName = this.domain.termsTableName;
var referenceTableName = this.domain.termsTableName;

var type = this.type;
var columnType = this.fieldTypeToColumnType(type);

if (type == 'uint' || type == 'literal') {
this.context.commandSync('table_create', {
name: this.alterTableName,
name: this.referenceTableName,
flags: nroonga.TABLE_HASH_KEY,
key_type: this.alterTableKeyType
key_type: this.referenceTableKeyType
});
alterTableName = this.alterTableName;
referenceTableName = this.referenceTableName;
}

this.context.commandSync('column_create', {
Expand All @@ -182,7 +182,7 @@ IndexField.prototype = {
type: columnType
});
this.context.commandSync('column_create', {
table: alterTableName,
table: referenceTableName,
name: this.indexColumnName,
flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS,
type: this.domain.tableName,
Expand All @@ -193,7 +193,7 @@ IndexField.prototype = {
var type = this.type;
if (type == 'uint' || type == 'literal') {
this.context.commandSync('table_remove', {
name: this.alterTableName
name: this.referenceTableName
});
}
this.context.commandSync('column_remove', {
Expand All @@ -206,19 +206,19 @@ IndexField.prototype = {
var type = this.type;
if (type == 'uint' || type == 'literal') {
this.context.commandSync('column_remove', {
table: this.alterTableName,
table: this.referenceTableName,
name: this.indexColumnName
});
this.context.commandSync('table_remove', {
name: this.alterTableName
name: this.referenceTableName
});
this.context.commandSync('table_create', {
name: this.alterTableName,
name: this.referenceTableName,
flags: nroonga.TABLE_HASH_KEY,
key_type: this.alterTableKeyType
key_type: this.referenceTableKeyType
});
this.context.commandSync('column_create', {
table: this.alterTableName,
table: this.referenceTableName,
name: this.indexColumnName,
flags: nroonga.INDEX_COLUMN_DEFAULT_FLAGS,
type: this.domain.tableName,
Expand Down
14 changes: 7 additions & 7 deletions test/database-index-field.test.js
Expand Up @@ -67,9 +67,9 @@ suite('database', function() {
'testdomain_' + Domain.DEFAULT_ID + '_valid_123');
});

test('alterTableName', function() {
test('referenceTableName', function() {
var field = new IndexField('valid_123', domain);
assert.equal(field.alterTableName,
assert.equal(field.referenceTableName,
'testdomain_' + Domain.DEFAULT_ID + '_valid_123');
});

Expand Down Expand Up @@ -271,9 +271,9 @@ suite('database', function() {
'table_create ' + domain.termsTableName + ' ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'table_create ' + field.alterTableName + ' ' +
'table_create ' + field.referenceTableName + ' ' +
'TABLE_HASH_KEY UInt32\n' +
'column_create ' + field.alterTableName + ' ' +
'column_create ' + field.referenceTableName + ' ' +
field.indexColumnName + ' ' +
'COLUMN_INDEX|WITH_POSITION ' + domain.tableName +
' ' + field.columnName;
Expand Down Expand Up @@ -314,15 +314,15 @@ suite('database', function() {
'table_create ' + domain.termsTableName + ' ' +
'TABLE_PAT_KEY|KEY_NORMALIZE ShortText ' +
'--default_tokenizer TokenBigram\n' +
'table_create ' + field.alterTableName + ' ' +
'table_create ' + field.referenceTableName + ' ' +
'TABLE_HASH_KEY ShortText\n' +
'column_create ' + field.alterTableName + ' ' +
'column_create ' + field.referenceTableName + ' ' +
field.indexColumnName + ' ' +
'COLUMN_INDEX|WITH_POSITION ' + domain.tableName +
' ' + field.columnName + '\n' +
'column_create ' + domain.tableName + ' ' +
field.columnName + ' COLUMN_SCALAR ' +
field.alterTableName;
field.referenceTableName;
assert.equal(dump, expected);
});

Expand Down

0 comments on commit 5bfd526

Please sign in to comment.