Repository navigation
Initial --params implementation - #12249
Conversation
|
Added tests (feat. I also added the bare words params, so There's also |
|
Do you think we should update the examples in query db so that the ones with |
|
I agree that it's unfortunate that they aren't immediately copy-pastable. In my defense, the original one that opened a .db file isn't reproducible without the file itself (which I assume never existed). It would require the examples having the store creation first, which would be two commands. It'd add more noise to the examples, IMO, but it's not unreasonable. It would also let us test the examples in the file itself. How would you do it? I'll take the chance to ask about |
You're on the right track with
Just to have a primary key. I don't think I allowed primary keys to be created otherwise. |
I know how to create a table, I'm more talking about the examples themselves. How would you format/write an example that involves two commands? Simply put the multiline example and it works? Didn't know of any other commands that did that, not even Also, even if I did it, it wouldn't work. Because
(nearly) All SQLite tables have an INTEGER PRIMARY KEY. This implicit, autoincrementing unique id is usually the primary index, and other non-integer primary keys are simply By adding an explicit If the user wants to optimize access patterns on the in-memory database, they should create an index with I can use (extra: here's the commands that work/fail with stor create's id column) |
|
Also, I would like for |
You could separate commands by semicolon.
I'm fine with removing the primary key as long as all the
|
|
I removed the default "id" column from I tried making the examples testable, but I had a few issues. Since I wanted to test with However, a bigger issue is that changes to the in-memory database didn't seem to be persisted between pipelines. I don't know why that is, If you want me to remove all test changes in the last commit, I can do that too. I technically added a bit of complexity to test_examples only to use them in an ignored test. |
|
@Dorumin How are you feeling about this PR now? Do you think it's ready to land? Are you happy with the test coverage? |
|
@fdncred I think I did what I wanted to for --params, it works for named and ordered values and all the ancillary work to make it function. I tested every case I could think of, but I don't know about exact code coverage since the workflow to check it was removed (when did that happen?) I'm surprised by how relatively untested I would've liked to test the examples too, but you can test them manually and see that the values check out. I'd say it's ready, yes. Do you agree? |
|
I don't think it's perfect but perfect is not a thing we deal in here. I think it's definitely an incremental step or two better, which is mostly all that I ever look for. Will this breaking change break people's code? I'm not sure but I'm ready to see. Thanks for your help. 🤞🏻 |
Description
This PR adds a
--paramsparam toquery db. This closes #11643.You can't combine both named and positional parameters, I think this might be a limitation with rusqlite itself. I tried using named parameters with indices like
{ ':named': 123, '1': "positional" }but that always failed with a rusqlite error. On the flip side, the other way around works: for something likeVALUES (:named, ?), you can treat both as positional:-p [hello 123].This PR introduces some very gnarly code repetition in
prepared_statement_to_nu_list. I tried, I swear; the compiler wasn't having any of it, it kept telling me to box my closures and then it said that the reference lifetimes were incompatible in the match arms. I gave up and put the mapping code in the match itself, but I'm still not happy.Another thing I'm unhappy about: I don't like how you have to put the
:colonin named parameters. I think nushell should insert it if it's missing. But this is the way rusqlite works, so for now, I'll let it be consistent. Just know that it's not really a blocker, and it isn't a compatibility change to later make{ colon: 123 }work, without the quotes and:. This would require allocating and turning our pretty little&strinto aString, thoughUser-Facing Changes
Less incentive to leave yourself open to SQL injection with statements like
query db $"INSERT INTO x VALUES \($unsafe_user_input)". Additionally, the$""syntax being annoying with parentheses plays in our favor, making users even more likely to use ? with--params.Tests + Formatting
Hehe