Skip to content
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

feat(db): allow primary key passed as full entity to DAOs #11695

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

bungle
Copy link
Member

@bungle bungle commented Oct 4, 2023

Summary

Previously you needed to write code like this:

local route = kong.db.routes:select_by_name("my-route")
kong.db.routes:update({ id = route.id }, {
  paths = { "/test" },
})
kong.db.routes:delete({ id = route.id })

with this change you can write it like this:

local route = kong.db.routes:select_by_name("my-route")
kong.db.routes:update(route, {
  paths = { "/test" },
})
kong.db.routes:delete(route)

Checklist

  • The Pull Request has tests
  • A changelog file has been added to CHANGELOG/unreleased/kong or adding skip-changelog label on PR if unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

@bungle
Copy link
Member Author

bungle commented Oct 4, 2023

A follow up for this PR would be to allow foreign keys to be given as full entities, like this:

Before:

local service = kong.db.services:insert({ url = "http://test.test/" })
local route = kong.db.routes:insert({
  paths = { "/test" },
  service = { id = service.id },
})

After:

local service = kong.db.services:insert({ url = "http://test.test/" })
local route = kong.db.routes:insert({
  paths = { "/test" },
  service = service,
})

@bungle bungle force-pushed the feat/db-entity-as-pk branch from 22899bd to 455222b Compare October 4, 2023 09:39
Copy link
Contributor

@nowNick nowNick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🚀

@bungle bungle force-pushed the feat/db-entity-as-pk branch from 455222b to 74e421e Compare October 19, 2023 17:43
@bungle bungle force-pushed the feat/db-entity-as-pk branch from 74e421e to 3db5788 Compare November 8, 2023 09:16
@bungle bungle removed the pr/discussion This PR is being debated. Probably just a few details. label Nov 8, 2023
@bungle bungle force-pushed the feat/db-entity-as-pk branch 4 times, most recently from 3e6c8ed to 6364a60 Compare November 8, 2023 15:46
@bungle bungle requested a review from samugi November 8, 2023 15:46
@bungle bungle marked this pull request as ready for review November 8, 2023 15:47
### Summary

Previously you needed to write code like this:
```lua
local route = kong.db.routes:select_by_name("my-route")
kong.db.routes:update({ id = route.id }, {
  paths = { "/test" }
})
kong.db.routes:delete({ id = route.id })
```

with this change you can write it like this:

```lua
local route = kong.db.routes:select_by_name("my-route")
kong.db.routes:update(route, {
  paths = { "/test" }
})
kong.db.routes:delete(route)
```

You can pass full entity to all the places that previously required the just the primary key.

Signed-off-by: Aapo Talvensaari <[email protected]>
@bungle bungle force-pushed the feat/db-entity-as-pk branch from 6364a60 to 7c477bc Compare November 8, 2023 15:50
Copy link
Member

@samugi samugi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@bungle bungle merged commit ef957a6 into master Nov 9, 2023
27 checks passed
@bungle bungle deleted the feat/db-entity-as-pk branch November 9, 2023 15:23
@bungle bungle added the cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee label Jan 25, 2024
@team-gateway-bot
Copy link
Collaborator

Cherry-pick failed for master, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-11695-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-11695-to-master-to-upstream
git checkout -b cherry-pick-11695-to-master-to-upstream
ancref=$(git merge-base 4b12b2394440ad8474fb16bde5081116da5983a3 7c477bcb2bfcba03ba674d9aa49823c487f4eaf0)
git cherry-pick -x $ancref..7c477bcb2bfcba03ba674d9aa49823c487f4eaf0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants