r/ryelang • u/middayc • Oct 28 '26
Practical example: Deduplicating records in database
Good things come in three-s, I hope, so here is another fully practical example of using Rye. This time I made a small, very problem specific script that looks at the contacts table and finds all the duplicate entries based on a VAT ID. And constructs and Excel table with that.
We send that Excel table to the client and they remove all the rows that they don't want de-duped.
Because this script has "human-in-the-loop" basically, I added a very light checksum column to the Excel, so the script that changes records doesn't run if the ID-s have been manually fiddled with.
In get-dupes, we could utilize the SQL more, and Rye tables, less, but I wrote whole script in Rye console interactively with --localhist flag and then cleaned up the local history file to get the code, moved code into functions and added some basic CLI flags spec. Rye now has Parse-args\full that accepts the args and spec, parses it, and in case of error shows the error and CLI flags generated help. That removes a bunch of boilerplate, but details still have to be fine-tuned.
Rye tables can hold all Rye values in their cells, also blocks, which shows very handy here, and group-by getting concat and concat-distinct few weeks back also!
Parse-args\full, checksum functions and some other details will be available with next release on github:
https://github.com/refaktor/rye
Otherwise I was working on XML parsing dialect for last week and hope to get to the final version with support for elegant data extraction soon. I will post about it ofc.
1
u/middayc Oct 29 '26
this is supposed to be a Python script that does roughly the same ... there are some differences with encoding of a block of id-s into xlsx.