Comparing version 0.0.8 to 0.0.9
@@ -74,3 +74,7 @@ const mysql = require('../mysql') | ||
const whereValue = this.conditions['updateWhere'][key] | ||
whereconditions.push(`${key} in ( ${mysql.escape(whereValue)} )`) | ||
if(Array.isArray(whereValue)) { | ||
whereconditions.push(`${key} in ( ${whereValue.map(d => mysql.escape(d)).join(',') } )`) | ||
} else { | ||
whereconditions.push(`${key} in ( ${mysql.escape(whereValue)} )`) | ||
} | ||
} | ||
@@ -77,0 +81,0 @@ SQL = `update ${this.table} set ${updateconditions.join(', ')} where ${whereconditions.join(' and ')}` |
{ | ||
"name": "h-orm", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/yuanhaoyu/h-orm.git", |
@@ -29,15 +29,14 @@ const horm = require('../../index') | ||
(async () => { | ||
test('find id = 1', async () => { | ||
expect(await StudentModel().find(1)).toEqual([{ name: 'man', sex: 1 }]) | ||
}) | ||
test('find id = 1,2', async () => { | ||
expect(await StudentModel().find([1,2])).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('find id = 1', async () => { | ||
expect(await StudentModel().find(1)).toEqual([{ name: 'man', sex: 1 }]) | ||
}) | ||
test('find id = 1,2', async () => { | ||
expect(await StudentModel().find([1,2])).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,18 +26,17 @@ | ||
const StudentModel = horm.model('teacher', { | ||
name: String, | ||
sex: Number, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test('insert one teacher', async () => { | ||
const result = await StudentModel().create({name: 1, sex: 0, status: 1}) | ||
expect(result.affectedRows).toEqual(1); | ||
}); | ||
test('insert three teacher', async () => { | ||
const result = await StudentModel().create([{name: 1, sex: 0, status: 1}, {name: '222', sex: 1, status: 1}, {name: '123131', sex: 0, status: 1}]) | ||
expect(result.affectedRows).toEqual(3); | ||
}); | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('insert one teacher', async () => { | ||
const result = await StudentModel().create({ name: 1, sex: 0, status: 1 }) | ||
expect(result.affectedRows).toEqual(1); | ||
}); | ||
test('insert three teacher', async () => { | ||
const result = await StudentModel().create([{ name: 1, sex: 0, status: 1 }, { name: '222', sex: 1, status: 1 }, { name: '123131', sex: 0, status: 1 }]) | ||
expect(result.affectedRows).toEqual(3); | ||
}); | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,33 +26,32 @@ | ||
const StudentModel = horm.model('student', { | ||
name: String, | ||
sex: Number, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test('like %ma%', async () => { | ||
expect(await StudentModel().like({name: '%ma%'})).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('like m%', async () => { | ||
expect(await StudentModel().like({name: 'm%'})).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('like %n', async () => { | ||
expect(await StudentModel().like({name: 'm%'})).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('no like %n', async () => { | ||
expect(await StudentModel().like({name: '%n', sex: 1}, 'NO', 'OR')).toEqual([ | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 }, | ||
]) | ||
}) | ||
test('like %ma%', async () => { | ||
expect(await StudentModel().like({ name: '%ma%' })).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('like m%', async () => { | ||
expect(await StudentModel().like({ name: 'm%' })).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('like %n', async () => { | ||
expect(await StudentModel().like({ name: 'm%' })).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
]) | ||
}) | ||
test('no like %n', async () => { | ||
expect(await StudentModel().like({ name: '%n', sex: 1 }, 'NO', 'OR')).toEqual([ | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,19 +26,18 @@ | ||
const StudentModel = horm.model('student', { | ||
name: String, | ||
sex: Number, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test('all limit 1', async () => { | ||
expect(await StudentModel().limit(1)).toEqual([{ name: 'man', sex: 1 }]) | ||
}) | ||
test('all limit 1 - 2', async () => { | ||
expect(await StudentModel().limit(1, 2)).toEqual([{ name: 'ww', sex: 0 }, { name: 'adad', sex: 1}]) | ||
}) | ||
test('all limit 0 - 3', async () => { | ||
expect(await StudentModel().limit(0, 3)).toEqual([{ name: 'man', sex: 1 }, { name: 'ww', sex: 0 }, { name: 'adad', sex: 1}]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('all limit 1', async () => { | ||
expect(await StudentModel().limit(1)).toEqual([{ name: 'man', sex: 1 }]) | ||
}) | ||
test('all limit 1 - 2', async () => { | ||
expect(await StudentModel().limit(1, 2)).toEqual([{ name: 'ww', sex: 0 }, { name: 'adad', sex: 1 }]) | ||
}) | ||
test('all limit 0 - 3', async () => { | ||
expect(await StudentModel().limit(0, 3)).toEqual([{ name: 'man', sex: 1 }, { name: 'ww', sex: 0 }, { name: 'adad', sex: 1 }]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,35 +26,34 @@ | ||
const StudentModel = horm.model('student', { | ||
name: String, | ||
sex: Number, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test('gel All student',async () => { | ||
expect(await StudentModel()).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 } | ||
]); | ||
}); | ||
test('where {sex: 0}', async () => { | ||
expect(await StudentModel().where({sex: 0})).toEqual([ | ||
{ name: 'ww', sex: 0 } | ||
]) | ||
}) | ||
test('where {sex: 0}', async () => { | ||
expect(await StudentModel().where({sex: ['0', '1']})).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 } | ||
]) | ||
}) | ||
test('where {sex: 0} or {sex: 1}', async () => { | ||
expect(await StudentModel().where({sex: 0, name: 'man'}, 'OR')).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('gel All student', async () => { | ||
expect(await StudentModel()).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 } | ||
]); | ||
}); | ||
test('where {sex: 0}', async () => { | ||
expect(await StudentModel().where({ sex: 0 })).toEqual([ | ||
{ name: 'ww', sex: 0 } | ||
]) | ||
}) | ||
test('where {sex: 0}', async () => { | ||
expect(await StudentModel().where({ sex: ['0', '1'] })).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'adad', sex: 1 } | ||
]) | ||
}) | ||
test('where {sex: 0} or {sex: 1}', async () => { | ||
expect(await StudentModel().where({ sex: 0, name: 'man' }, 'OR')).toEqual([ | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,38 +26,37 @@ | ||
const StudentModel = horm.model('student', { | ||
name: String, | ||
sex: Number, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test('sort by name asc', async () => { | ||
expect(await StudentModel().sort({key: 'name', rule: 'ASC'})).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('sort by name desc', async () => { | ||
expect(await StudentModel().sort({key: 'name', rule: 'DESC'})).toEqual([ | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'adad', sex: 1 }, | ||
]) | ||
}) | ||
test('sort by name and sex asc', async () => { | ||
expect(await StudentModel().sort([{key: 'name', rule: 'ASC'}, {key: 'sex', rule: 'ASC'}])).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('sort by name and sex asc', async () => { | ||
expect(await StudentModel().sort([{key: 'name', rule: 'ASC'}, {key: 'sex', rule: 'DESC'}])).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test('sort by name asc', async () => { | ||
expect(await StudentModel().sort({ key: 'name', rule: 'ASC' })).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('sort by name desc', async () => { | ||
expect(await StudentModel().sort({ key: 'name', rule: 'DESC' })).toEqual([ | ||
{ name: 'ww', sex: 0 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'adad', sex: 1 }, | ||
]) | ||
}) | ||
test('sort by name and sex asc', async () => { | ||
expect(await StudentModel().sort([{ key: 'name', rule: 'ASC' }, { key: 'sex', rule: 'ASC' }])).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('sort by name and sex asc', async () => { | ||
expect(await StudentModel().sort([{ key: 'name', rule: 'ASC' }, { key: 'sex', rule: 'DESC' }])).toEqual([ | ||
{ name: 'adad', sex: 1 }, | ||
{ name: 'man', sex: 1 }, | ||
{ name: 'ww', sex: 0 }, | ||
]) | ||
}) | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
@@ -5,17 +5,17 @@ const horm = require('../../index') | ||
const windows = { | ||
host : '127.0.0.1', | ||
port : '3306', | ||
user : 'root', | ||
password : 'root', | ||
database : 'test', | ||
debug : true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
user: 'root', | ||
password: 'root', | ||
database: 'test', | ||
debug: true | ||
} | ||
const mac = { | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
host: '127.0.0.1', | ||
port: '3306', | ||
database: 'test', | ||
user: '', | ||
password: '', | ||
debug: true | ||
} | ||
@@ -26,22 +26,31 @@ | ||
const StudentModel = horm.model('teacher', { | ||
id: String, | ||
name: String, | ||
sex: Number, | ||
id: String, | ||
name: String, | ||
sex: Number, | ||
}); | ||
(async () => { | ||
test(`delete one`,async () => { | ||
await StudentModel().create({name: 'aaa', sex: 0}) | ||
const allTeacher = await StudentModel() | ||
const result = await StudentModel().delete(allTeacher[allTeacher.length - 1].id) | ||
expect(result.changedRows).toEqual(1); | ||
}); | ||
test(`update where sex = 3`,async () => { | ||
await StudentModel().create([{name: 'aaa', sex: 3}, {name: 'aaa', sex: 3}]) | ||
const result = await StudentModel().update({sex: 0}, { sex: 3}) | ||
expect(result.changedRows).toEqual(2); | ||
}); | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) | ||
})() | ||
test(`delete one`, async () => { | ||
await StudentModel().create({ name: 'aaa', sex: 0 }) | ||
const allTeacher = await StudentModel() | ||
const result = await StudentModel().delete(allTeacher[allTeacher.length - 1].id) | ||
expect(result.changedRows).toEqual(1); | ||
}); | ||
test(`update where sex = 3`, async () => { | ||
await StudentModel().create([{ name: 'aaa', sex: 3 }, { name: 'aaa', sex: 3 }]) | ||
const result = await StudentModel().update({ sex: 0 }, { sex: 3 }) | ||
expect(result.changedRows).toEqual(2); | ||
}); | ||
test(`update where sex = 3 and name = b`, async () => { | ||
await StudentModel().create([{ name: 'das', sex: 4 }, { name: 'b', sex: 3 }]) | ||
const result = await StudentModel().update({ sex: 9 }, { sex: 3, name: 'b' }) | ||
expect(result.changedRows).toEqual(1); | ||
}); | ||
test(`update where name in b1, b2`, async () => { | ||
await StudentModel().create([{ name: 'b1', sex: 5 }, { name: 'b2', sex: 5 }]) | ||
const result = await StudentModel().update({ sex: 6 }, { name: ['b1', 'b2'] }) | ||
expect(result.changedRows).toEqual(2); | ||
}); | ||
test('close mysql here', () => { | ||
mysql.close() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
573
22065
16