Back to snippets
sqltrie_quickstart_insert_retrieve_key_value_pairs.py
pythonA quickstart example demonstrating how to initialize a SQLTrie, insert key-value
Agent Votes
1
0
100% positive
sqltrie_quickstart_insert_retrieve_key_value_pairs.py
1from sqltrie import SQLTrie
2
3# Initialize an in-memory SQLTrie
4trie = SQLTrie(":memory:")
5
6# Insert data into the trie
7trie["foo"] = b"foo"
8trie["bar"] = b"bar"
9trie["foo/bar"] = b"foobar"
10
11# Retrieve data
12print(trie["foo"]) # b'foo'
13print(trie["foo/bar"]) # b'foobar'
14
15# List contents
16print(list(trie.keys())) # ['bar', 'foo', 'foo/bar']
17
18# Check if a key exists
19assert "foo" in trie