[TinyDB] How to replace an "item"?

(SVasco) #1

Hi:

I have a TinyDB like this:
Tag=Users
Value=Peter;[email protected];40#Hana;[email protected];30

2 records as a simple example:
Peter;[email protected];40 <— Index 1
Hana;[email protected];30 <— Index 2
Idx1_______Idx2_______Idx3

How can I replace, for example, the “item” "[email protected]" text?

Can someone plz give a function block example, to replace an “item”, with an option to select the “Index” of a record and a Idx of the value?

A function to run like this:
061343c7dac1cb7e7fc120f3b8b2b9dc

Thank you.

(Cian) #2

Treat your tags as a list and nested list. So your first list is separated by #, your sublist is separated by ;

You are trying to change Item 2, in List 1 of List 1.

There are two ways to do it. First is you try to parse the list and lists of list, replace the index, and then rebuild…

OR . (easiest)

Use this block. If you know what it was BEFORE the change (which you need to know anyway), and your know what it will be after the change, then use this block on the value. Don’t over complicate it :slight_smile:

image

(SVasco) #3

Thank you @cian!

Well, I can find an item:
061343c7dac1cb7e7fc120f3b8b2b9dc

Tag=Users
Value=Peter;[email protected];40#Hana;[email protected];30

[email protected]

But I cant find a way to store/save it on the TinyDB :thinking:

(Cian) #4

You have to reassemble the “list”

You can use the “join” command. I don’t think it is practical.

Remember TinyDB does not see this as a list. It sees it as a string of text. So the best way to do it is once you get your result, now use the Replace All Text to replace the text in the value, and then write it again.

You can use your list logiv to extract it, and the replace logic to replace it

image

(SVasco) #5

@cian:

I’m not sure what to do in the end:
061343c7dac1cb7e7fc120f3b8b2b9dc

(Cian) #6

This should be tmp

(SVasco) #7

Thank you @cian!

1 Like