Skip to content

Instantly share code, notes, and snippets.

@delijati
Created September 29, 2017 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delijati/49f9b6c5d3e9eb79d7468226796900ba to your computer and use it in GitHub Desktop.
Save delijati/49f9b6c5d3e9eb79d7468226796900ba to your computer and use it in GitHub Desktop.
dataset + flatdict
import flatdict
values = {'foo': {'bar': {'baz': 0,
'qux': 1,
'corge': 2},
'grault': {'baz': 3,
'qux': 4,
'corge': 5}},
'garply': {'foo': 0, 'bar': 1, 'baz': 2, 'qux': {'corge': 3}}}
flat = flatdict.FlatDict(values)
import dataset
db = dataset.connect('sqlite:///:memory:')
table = db['sometable']
table.insert(flatdict.FlatDict(values))
table.find_one(**{'foo:bar:corge': 2})
flatdict.FlatDict(table.find_one(**{'foo:bar:corge': 2})).as_dict()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment