-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Association query #19
Conversation
9153b62
to
eb765b1
Compare
Coverage increased (+0.06%) to 96.4% when pulling eb765b1d323d0f3ae6d5ce714014cd3097ac38da on feature/association-query into ce214b2 on master. |
eb765b1
to
8c97a5b
Compare
Coverage increased (+0.06%) to 96.4% when pulling 8c97a5bf0bd34d179e98a2bd0138b8eaa394ac07 on feature/association-query into ce214b2 on master. |
这个是已经实现好了呀? |
@Saviio 嗯嗯,代码看过,但还没理解这个 PR 要达到的效果,今天再看看 👌 |
达到的效果是: transform {
fields: [....],
where: {
'creator.gender': 'male'
}
} to SELECT
_id,
Member.id,
Member.name,
Member.gender
FROM Message
JOIN Member ON Message.creatorId = Member.id
WHERE Member.gender = 'male' |
src/storage/Database.ts
Outdated
@@ -445,7 +449,8 @@ export class Database { | |||
mainTable: table! | |||
} | |||
const { limit, skip } = clause | |||
const provider = new PredicateProvider(table!, clause.where) | |||
const tables = this.getAssoTablesDef(db, tableName, table) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Brooooooklyn 这边 tableName 和 table 可能不一致吗?
@Brooooooklyn 我第一次注意到 createPredicate 这个函数,根据目前的实现,它的作用应该已经被现在的 PredicateProvider (可以处理空的 null 或 undefined 的 clause)代替了,还需要保留它吗? |
可以保留,配合 try {
new PredicateProvider(xxxxx).getPredicate()
// success logic
} catch (e) {
// error logic
} 的语法糖 |
385b4b8
to
4ef39fe
Compare
Coverage decreased (-0.06%) to 96.28% when pulling 4ef39feb47ef967faaced5ca1755d3e79c178461 on feature/association-query into ce214b2 on master. |
4ef39fe
to
fa72de7
Compare
Coverage increased (+0.08%) to 96.413% when pulling fa72de7d08cd9b45f2d53ed11108f4f8e0d630fa on feature/association-query into ce214b2 on master. |
expect(result).to.deep.equal(innerTarget) | ||
}) | ||
|
||
it.skip('should get association by deep nested Association query without association fields', function* () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need some help here @Saviio
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
蛤? 有啥问题
src/storage/Database.ts
Outdated
@@ -747,6 +759,22 @@ export class Database { | |||
} | |||
} | |||
|
|||
private getAssoTablesDef(db: lf.Database, tableName: string, defaultTable: null | lf.schema.Table = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getRelatedTables
我现在的做法是:
{
[index: string]: {
table: lf.schema.Table
contextName: string
}
}
{
'Task#1': {
table: tableClass, // alias Task#1,
contextName: 'Task#1'
},
'Task#1@project': {
table: tableClass, // alias Project#1
contextName: Project#1
},
'Project#1@organization': {
table: tableClass, // alias Organization#1
contextName: Organization#1
}
}
这样做有一个问题就是,当 query 的 predicate 中指定了某个关联的条件,但 fields 中并不包含这个关联的时候会构建不出 tablesStructure, 比如: Database.get('Task', {
fields: ['_id'],
where: {
'project.organization._id': 'xxxx'
}
}) 具体表现就是 |
fa72de7
to
49f7801
Compare
Coverage increased (+0.08%) to 96.413% when pulling 49f780161e544c70a93f43884125f359b9b04515 on feature/association-query into ce214b2 on master. |
4877b5e
to
cdafc68
Compare
ready |
5f161a0
to
77e98bd
Compare
77e98bd
to
68fb8fe
Compare
68fb8fe
to
541b338
Compare
274b5e4
to
ac32a6d
Compare
}) | ||
}) | ||
|
||
it('should warn if build addition join info from predicate failed', function* () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo additional
@@ -1049,9 +1205,7 @@ export default describe('Database Testcase: ', () => { | |||
const execRet1 = yield database.upsert<ProgramSchema>('Program', program) | |||
|
|||
yield database.delete<ProgramSchema>('Program', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里接口不对称真的好吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 的,get 才需要 fields,skip limit order 这些
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我明白,但是我还认为应该把接口设计的更对称,从形式上更接近
DELETE FROM table WHERE id > 0
这里的省略是一种"习惯的破坏"
@@ -539,21 +695,6 @@ export default describe('Database Testcase: ', () => { | |||
}) | |||
}) | |||
|
|||
it('should throw if only navigator was included in query', function* () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
咦,为什么删了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
行为变了,默认会在所有的 associated query 上加上 pk
expect(result.project.organization._id).to.equal(innerTarget.project._organizationId) | ||
}) | ||
|
||
it('should merge fields when get value by deep nested Association query with nested association fields', function* () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should merge fields if a nested association in the WHERE clause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
剩下的明天再看,脑子转不动了
… to merge query.fields & fields built from predicate
…predicate reduce the logics in Database#buildSelector and PredicateProvider#normalizeMeta
feat(Database): Only navigation properties in query now valid
ac32a6d
to
d78d3a1
Compare
src/storage/Database.ts
Outdated
@@ -745,6 +785,115 @@ export class Database { | |||
} | |||
} | |||
|
|||
private buildTablesStructure(defaultTable: lf.schema.Table, aliasName?: string, tablesStruct: TablesStruct = Object.create(null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数叫 tablesStructure 有点奇怪....."复数的表"的结构,我觉得这系列函数名/变量的命名不如就叫tableStruct
ba7a13a
to
9e7db4a
Compare
Association query
Breaking Changes
Related Issue:
resolve #14