walinejs / dittorm Goto Github PK
View Code? Open in Web Editor NEWA Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.
License: MIT License
A Node.js ORM for MySQL, SQLite, PostgreSQL, MongoDB, GitHub and serverless service like Deta, InspireCloud, CloudBase, LeanCloud.
License: MIT License
测试小Demotest.js
const Model = require('dittorm')('mongodb')
const admin = new Model('D_admin', { database: 'Discuss' })
async function run() {
// 查看所有数据
const data1 = await admin.select({})
console.log('data1', data1)
// 单字段模糊查询
const data2 = await admin.select({ avatarCdn: ['LIKE', '%avatar%'] })
console.log('data2', data2)
// 多字段模糊查询
const data3 = await admin.select({
_complex: {
avatarCdn: ['LIKE', '%avatar%'],
siteUrl: ['LIKE', '%avatar%'],
serverURLs: ['LIKE', '%avatar%'],
_logic: 'OR'
}
})
console.log('data3', data3)
}
run()
执行node test.js
输入如下
Lete@Lete MINGW64 /l/Coding/Code/Nodejs/Discuss/dev (dev)
$ node test
mongodb://127.0.0.1:27017/Discuss
data1 [
{
username: 'admin111',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: '0',
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '随意更改的数据用于测试:avatar',
serverURLs: '看看多多字段模糊查询是否能匹配avatar',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
},
{
username: 'admin222',
avatarCdn: 'https://cravatar.cn/avatar/',
id: '821f335abb5703508cb58cad'
},
{
username: 'admin333',
siteUrl: '随意更改的数据用于测试:avatar',
id: '921f335abb5703508cb58ca9'
}
]
data2 [
{
username: 'admin111',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: '0',
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '随意更改的数据用于测试:avatar',
serverURLs: '看看多多字段模糊查询是否能匹配avatar',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
},
{
username: 'admin222',
avatarCdn: 'https://cravatar.cn/avatar/',
id: '821f335abb5703508cb58cad'
}
]
(node:3692) UnhandledPromiseRejectionWarning: MongoError: unknown top level operator: $OR. If you have a field name that starts with a '$' symbol, consider using $getField or $setField.
at MessageStream.messageHandler (L:\Coding\Code\Nodejs\Discuss\dev\node_modules\mongodb\lib\cmap\connection.js:299:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (L:\Coding\Code\Nodejs\Discuss\dev\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (L:\Coding\Code\Nodejs\Discuss\dev\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (_stream_writable.js:352:12)
at MessageStream.Writable.write (_stream_writable.js:303:10)
at Socket.ondata (_stream_readable.js:719:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:284:9)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:3692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3692) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
const Model = require('dittorm')('mongodb')
const admin = new Model('D_admin', { database: 'Discuss' })
admin.select({}).then((data) => {
console.log(data)
/*
返回结果:
[
{
username: 'admin',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: 0,
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '',
serverURLs: '',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
}
]
*/
})
// 根据上方得到的返回结果,根据id查询,是否返回同样数据
admin.select({ id: '621f335abb5703508cb58caf' }).then((data) => {
console.log(data)
/*
返回数据: []
*/
})
// 查询_id字段
admin.select({ _id: '621f335abb5703508cb58caf' }).then((data) => {
console.log(data)
/*
返回数据: []
*/
})
// 根据username
admin.select({ username: 'admin' }).then((data) => {
console.log(data)
/*
返回数据:
[
{
username: 'admin',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: 0,
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '',
serverURLs: '',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
}
]
*/
})
/*
该代码执行后4个console.log()的结果如下
[
{
username: 'admin',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: 0,
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '',
serverURLs: '',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
}
]
[]
[]
[
{
username: 'admin',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: 0,
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '',
serverURLs: '',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
}
]
*/
测试小Demotest.js
const Model = require('dittorm')('mongodb')
const admin = new Model('D_admin', { database: 'Discuss' })
async function run() {
// 查看所有数据
const data1 = await admin.select({})
console.log('data1', data1)
// 查询vip用户
const data2 = await admin.select({ vip: true })
console.log('data2', data2)
}
run()
输出结果
Lete@Lete MINGW64 /l/Coding/Code/Nodejs/Discuss/dev (dev)
$ node test
mongodb://127.0.0.1:27017/Discuss
data1 [
{
username: 'admin111',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: '0',
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '随意更改的数据用于测试:avatar',
serverURLs: '看看多多字段模糊查询是否能匹配avatar',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
},
{
username: 'admin222',
avatarCdn: 'https://cravatar.cn/avatar/',
id: '921f335abb5703508cb58ca9'
},
{ username: 'admin333', vip: true, id: '62209a95592e000071002bf4' }
]
data2 [
{
username: 'admin111',
password: '$2a$10$3OhJu5DRU3pDViuxEdaipe6lMbutdcaELYk8aW0SM1xquX.kD68iG',
mail: '',
domain: '',
requestHeaders: '',
commentCount: 6,
wordNumber: '0',
limit: 0,
limitAll: 0,
akismet: '',
avatarCdn: 'https://cravatar.cn/avatar/',
siteUrl: '随意更改的数据用于测试:avatar',
serverURLs: '看看多多字段模糊查询是否能匹配avatar',
mailHost: '',
mailPort: '',
mailFrom: '',
mailAccept: '',
masterSubject: '',
masterTemplate: '',
replySubject: '',
replyTemplate: '',
id: '621f335abb5703508cb58caf'
},
{
username: 'admin222',
avatarCdn: 'https://cravatar.cn/avatar/',
id: '921f335abb5703508cb58ca9'
},
{ username: 'admin333', vip: true, id: '62209a95592e000071002bf4' }
]
如下图,在查询过程中,我指定了查询条件path
为/guide/API-Docs.html
,我的预期是查询出path
是/guide/API-Docs.html
的数据,而实际的结果却是查询了所有数据。
据我判断,这因该是#154行为使用where()
导致的问题 CloudBase 文档示例
另外我还有一个疑问,关于do while
的判断条件#171行,只有ret.length等于100才会停止,那么如果我只有1-5条数据或是大于100条,那么这不就是无限循环了?
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are currently rate-limited. Click on a checkbox below to force their creation now.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.github/workflows/codeql-analysis.yml
actions/checkout v3
github/codeql-action v2
github/codeql-action v2
github/codeql-action v2
package.json
@byteinspire/api ^1.0.12
@cloudbase/node-sdk ^2.7.1
deta ^1.0.2
fast-csv ^4.3.6
leancloud-storage ^4.12.2
mongodb ^4.0.0
tablestore ^5.1.1
think-helper ^1.1.3
think-model ^1.5.4
think-model-mysql ^1.1.6
think-model-postgresql ^1.1.7
think-mongo ^2.1.2
undici ^5.0.0
@types/mysql 2.15.21
@types/node 17.0.21
@types/pg 8.6.5
ava 4.3.1
dotenv 16.0.1
nyc 15.1.0
typescript 4.7.4
think-model-sqlite ^1.2.2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.