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

auto alter table schema #97

Closed
kkharji opened this issue Aug 24, 2021 · 1 comment · Fixed by #102
Closed

auto alter table schema #97

kkharji opened this issue Aug 24, 2021 · 1 comment · Fixed by #102
Labels
enhancement New feature or request

Comments

@kkharji
Copy link
Owner

kkharji commented Aug 24, 2021

It's really annoying to have to call table drop or keep track of schema.ensure. In nvim-telescope/telescope-frecency.nvim#35, I was trying to debug and understand why count field keep being nil, even though the schema has default=0. It turns out the calling files.schema() returned an old schema, which means that the new schema has not effect on pre-existing table.

I'd like to compare the sql table schema and user provided schema and compare
between them, and if they are different. I'd like table module to auto alter.

The full table schema information as it exists in C side can be found with db:schema("files", true), it output something like that

{
  def = {},
  info = {
    count = { cid = 0, primary = false, required = false, type = "INTEGER" },
    id = { cid = 1, primary = true, required = false, type = "INTEGER" },
    path = { cid = 2, primary = false, required = false, type = "TEXT" }
  },
  req = {},
  types = { count = "INTEGER", id = "INTEGER", path = "TEXT" }
}

In telescope-frecency case, I wanted it to change to the following:

{
  def = { count = "0" },
  info = {
    count = { cid = 0, default = "0", primary = false, required = false, type = "integer" },
    id = { cid = 1, primary = true, required = true, type = "integer" },
    path = { cid = 2, primary = false, required = false, type = "string" }
  },
  req = {},
  types = { count = "integer", id = "integer", path = "string" }
}
@kkharji kkharji added the enhancement New feature or request label Aug 24, 2021
@kkharji kkharji added this to the 0.1 milestone Aug 24, 2021
@kkharji kkharji reopened this Aug 26, 2021
@kkharji
Copy link
Owner Author

kkharji commented Aug 27, 2021

when #103 is merged. Table schema keys can be changed on the fly.

@kkharji kkharji removed this from the 0.1 milestone Aug 28, 2021
@kkharji kkharji closed this as completed Sep 2, 2021
muniter pushed a commit to muniter/sql.nvim that referenced this issue Sep 30, 2021
still compatible with query as first argument ✅  

Examples:

```lua
tbl:each(function(row) .. end) -- execute a function on all table rows
tbl:each(function(row) .. end, {...} ) -- execute a function on all table rows match the query
-- map work the same way, but return transformed table
```

closes kkharji#97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant