Open sirex opened 1 year ago
python - ~/.local/share/spinta/keymap.db datasets/gov/example/Data 264ae0f9-53eb-496b-a07c-ce1b9cbe510c <<'EOF'
import sys, os, msgpack, hashlib
import sqlalchemy as sa
keymap, table, key = sys.argv[1:]
keymap = os.path.expanduser(keymap)
engine = sa.create_engine(f'sqlite:///{keymap}')
meta = sa.MetaData(engine)
meta.reflect()
table = meta.tables[table]
with engine.connect() as conn:
query = sa.select([table]).where(table.c.key == key)
for row in conn.execute(query):
val = msgpack.loads(row.value)
print(f'{key} -> {val}')
EOF
When trying to understand an issue with data, it is often important to know, what is inside a keymap.db file. One can open keymap.db file, with an SQLite database manager and look what is inside, but since local identifiers are encoded with MsgPack and hashed with SHA1, it is not always easy to find what you are looking for.
It is possible, to get hashed value using following oneliner:
But this is not very convenient and user friendly.
So it would be nice to have something like this:
Here, we given a model name, and an global id and command returns local id.
Alternatively, we can do same thing in reverse:
Command with
--global
flag, should cast11
to integer if property inmodel.ref
isinteger
type.