-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: computed fields support for functions and one to many relations…
…hip lookups (#1711)
- Loading branch information
Showing
41 changed files
with
1,339 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
"-d", | ||
"${input:directory}", | ||
"--pattern", | ||
"${input:pattern}" | ||
"${input:pattern}", | ||
] | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
integration/testdata/computed_fields_circular_ref/schema.keel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
model Account { | ||
fields { | ||
balance Decimal @computed(SUM(account.transactions.total)) | ||
transactions Transaction[] | ||
standardTransactionFee Decimal | ||
} | ||
actions { | ||
create createAccount() with (standardTransactionFee) { | ||
@permission(expression: true) | ||
} | ||
list listAccounts() { | ||
@permission(expression: true) | ||
} | ||
get getAccount(id) { | ||
@permission(expression: true) | ||
} | ||
} | ||
} | ||
|
||
model Transaction { | ||
fields { | ||
account Account | ||
amount Decimal | ||
fee Decimal? @computed(transaction.account.standardTransactionFee) | ||
total Decimal? @computed(transaction.amount + transaction.fee) | ||
} | ||
actions { | ||
create createTransaction() with (account.id, amount) { | ||
@permission(expression: true) | ||
} | ||
get getTransaction(id) { | ||
@permission(expression: true) | ||
} | ||
list listTransactions() { | ||
@permission(expression: true) | ||
} | ||
} | ||
} | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
integration/testdata/computed_fields_circular_ref/tests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { test, expect, beforeEach } from "vitest"; | ||
import { models, resetDatabase, actions } from "@teamkeel/testing"; | ||
|
||
beforeEach(resetDatabase); | ||
|
||
test("computed fields - circular reference", async () => { | ||
const account = await models.account.create({ standardTransactionFee: 10 }); | ||
const transaction1 = await models.transaction.create({ | ||
accountId: account.id, | ||
amount: 100, | ||
}); | ||
const transaction2 = await models.transaction.create({ | ||
accountId: account.id, | ||
amount: 200, | ||
}); | ||
|
||
const getAccount = await models.account.findOne({ id: account.id }); | ||
expect(getAccount!.balance).toBe(320); | ||
}); |
50 changes: 50 additions & 0 deletions
50
integration/testdata/computed_fields_one_to_many/schema.keel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
model Invoice { | ||
fields { | ||
items Item[] | ||
shipping Number | ||
total Decimal @computed(SUM(invoice.items.product.price) + invoice.shipping) | ||
} | ||
actions { | ||
get getInvoice(id) { | ||
@permission(expression: true) | ||
} | ||
create createInvoice() with (shipping, items.product.id?) { | ||
@permission(expression: true) | ||
} | ||
list listInvoices() { | ||
@permission(expression: true) | ||
} | ||
} | ||
} | ||
|
||
model Item { | ||
fields { | ||
invoice Invoice | ||
product Product | ||
} | ||
actions { | ||
get getItem(id) { | ||
@permission(expression: true) | ||
} | ||
create createItem() with (product.id, invoice.id) { | ||
@permission(expression: true) | ||
} | ||
} | ||
} | ||
|
||
model Product { | ||
fields { | ||
price Decimal | ||
} | ||
actions { | ||
get getProduct(id) { | ||
@permission(expression: true) | ||
} | ||
create createProduct() with (price) { | ||
@permission(expression: true) | ||
} | ||
list listProducts() { | ||
@permission(expression: true) | ||
} | ||
} | ||
} |
Oops, something went wrong.