sqlitedict icon indicating copy to clipboard operation
sqlitedict copied to clipboard

Feature Proposal: SqliteList

Open annovialb opened this issue 3 years ago • 4 comments

Hello, I am a happy user of the SqliteDict. Thanks for making it!

I would like to store a list as a table in the same sql file. At the moment, in order to use the same sql file, I am storing the list as a value inside a dict. This is highly inefficient since to add an element, I rewrite the whole list to sql.

I think it would be a pretty useful feature. Just my 2 cents :)

annovialb avatar Jul 31 '22 19:07 annovialb

I have same idea, after I think about this idea twice it's not as simple as it looks, how do you implement a List over sql database? definitely involve save additional information to work row as doubly linked list data structure which might hurt performance, left my 2 cents here I might implement a simple one for fun.

AndCycle avatar Aug 12 '22 17:08 AndCycle

Hi, thanks for they reply. I am not sure what a good implementation of a List in sql would be. I am just throwing in a 2 cent idea. The primary key could be a floating point number stored as a string (or just float). As the first elements are inserted, they are stored with key "0.", "1.", "2." ... Inserting element(s) could use intermediate float values e.g. "1.5" then "1.75" to insert 2 elements in between "1." and "2.".

We are at 6 cents so far :)

annovialb avatar Aug 21 '22 20:08 annovialb

One can write a list-like wrapper around the sqlitedict, as a stopgap until this is implemented as a feature.

Here is what I did https://github.com/za3k/day29_adventure/blob/master/base.py#L18 . It's definitely not perfect performance-wise, just an example.

za3k avatar Nov 30 '22 06:11 za3k

Why not put the lists in their own table according to standard database normalization?

WolfgangFahl avatar Feb 19 '23 07:02 WolfgangFahl