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

db: add methods to delete a channel or nick's key from database #1526

Merged

Conversation

deathbybandaid
Copy link
Contributor

@deathbybandaid deathbybandaid commented Mar 28, 2019

These are functions I've had for my bot for a long time,

  • reset - sets a value to None
  • adjust - allows math adjustments to existing values

Reset can likely use a better method like DELETE FROM instead of replacing values with None.

Adjust is something I've been using for a long time now to retrieve a current value and add a positive or negative number to it. Handy for modules that need to update stat counters.

@dgw
Copy link
Member

dgw commented Mar 28, 2019

It's easy to 👍 a function to delete values from the database, though I would definitely name the functions delete_{nick|channel}_value() rather than reset (and use a DELETE statement to match the name instead of setting the value to None).

Getting on board with an adjustment function is much harder. Sopel's database doesn't care what you put in it—everything becomes strings under the hood. Because of that, I don't think the db layer is a good place to put manipulator functions. Changing a value in the DB is more of a "program logic" operation, and I say the code to do it should live in the program (read: plugin) that wants to do it.

@Exirel
Copy link
Contributor

Exirel commented Mar 29, 2019

I agree with @dgw.

I would like to point out that Sopel's DB interface will be modified for 7.x, by using SQLAlchemy. So if you want to add or change DB-related features, I invite you to either wait for #1446 to be merged, or to base your work on this branch (but that's risky, considering it's a very living branch with rebase every now and then).

@dgw
Copy link
Member

dgw commented Mar 29, 2019

Well it's not changing much at this point, but I agree that rebasing onto a branch that has been rebased is annoying.

Shouldn't be long, though!

@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from ba384bc to 7d2f5c0 Compare May 1, 2019 18:57
@deathbybandaid deathbybandaid changed the title Add database functionality for resetting values, and mathmatical adjusts Add database functionality for resetting values May 1, 2019
@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 7d2f5c0 to 8743a3c Compare May 1, 2019 19:01
@deathbybandaid
Copy link
Contributor Author

I removed the adjust_ and figured out how to properly DELETE via sqlite

@Exirel Exirel changed the title Add database functionality for resetting values db: add a delete channel or nick's key from database May 1, 2019
@Exirel Exirel changed the title db: add a delete channel or nick's key from database db: add methods to delete a channel or nick's key from database May 1, 2019
Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

Straightforward, yet naming things is still hard! 😉

sopel/db.py Outdated Show resolved Hide resolved
sopel/db.py Outdated Show resolved Hide resolved
Exirel
Exirel previously approved these changes May 8, 2019
@Exirel Exirel dismissed their stale review May 8, 2019 13:45

Waiting for #1446 to be merged first.

@dgw
Copy link
Member

dgw commented May 12, 2019

Reminder for myself (and/or the ambitious PR owner) to give the function names and docstrings a good once-over after this is reworked on top of SQLAlchemy/#1446. (I still prefer _value to _key in the names, and "delete" instead of "reset" in the docs.)

@dgw
Copy link
Member

dgw commented May 12, 2019

Ready to rework, @deathbybandaid. #1446 just merged in. ☺

@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 7e2d78d to 523e86c Compare May 13, 2019 17:20
@deathbybandaid
Copy link
Contributor Author

Assuming #1603 gets fixed, my research shows that this is how to delete a value via sqlalchemy. This will need some testing pending that fix.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I'm pretty sure you want to call session.delete(result) (not result.value), but I'd get confirmation from @RustyBower on that one since he has much more SQLAlchemy experience than any of the rest of us.

Going off of https://stackoverflow.com/a/26643978/5991 fwiw

sopel/db.py Outdated Show resolved Hide resolved
@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 523e86c to 628c927 Compare May 13, 2019 22:50
@RustyBower
Copy link
Contributor

Yeah it's definitely session.delete(result), otherwise you're gonna run into errors.

@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 628c927 to 88f2ed2 Compare May 15, 2019 14:01
@deathbybandaid
Copy link
Contributor Author

Applied suggestions

Copy link
Contributor

@Exirel Exirel left a comment

Choose a reason for hiding this comment

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

LGTM

@dgw dgw closed this May 28, 2019
@dgw dgw reopened this May 28, 2019
@dgw
Copy link
Member

dgw commented May 28, 2019

Closed/reopened to kick Scrutinizer in the pants (it errored during the last inspection and I didn't notice until this weekend). I guess we'll also get a new Travis build out of it, so yay?

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

One wee copy-and-paste leftover to fix, and then I think this is ready.

sopel/db.py Outdated Show resolved Hide resolved
@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 95585fa to 31a95a6 Compare May 29, 2019 10:29
@deathbybandaid
Copy link
Contributor Author

updated, and squashed

@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from 77ae01d to f45825b Compare May 29, 2019 11:58
@deathbybandaid
Copy link
Contributor Author

I went an added step and added tests

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I'm 99% 👍; just want to make these two docstrings consistent with their siblings.

sopel/db.py Outdated Show resolved Hide resolved
sopel/db.py Outdated Show resolved Hide resolved
@deathbybandaid deathbybandaid force-pushed the database-functionality-additions branch from e6e93ca to ddb9617 Compare June 30, 2019 21:02
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

🎉 🙏

@dgw dgw merged commit c9659e0 into sopel-irc:master Jul 2, 2019
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