simonw / simonw/sqlite-utils

Feature request: sqlite-utils insert-files should be able to convert fields

Open
#597 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.2k
Forks
172
Avg merge
9m
Merged PRs (30d)
1

Description

Currently using both insert-files and convert is needed in order to create sqlar files, it would be more convenient if it could be done with just one command.

~
❯ cat test.py
import os

class Example:
    def __init__(self, arg1, arg2):
        self.arg1 = arg1

~
❯ sqlite-utils insert-files test.sqlar sqlar test.py -c name:name -c data:content -c mode:mode -c mtime:mtime -c sz:size --pk=name
  [####################################]  100%

~
❯ sqlite-utils convert test.sqlar sqlar data "zlib.compress(value)" --import=zlib --where "name = 'test.py'"
[####################################]  100%

~
❯ cat test.py | sqlite-utils convert test.sqlar sqlar data "zlib.compress(sys.stdin.buffer.read())" --import=zlib --import=sys --where "name = 'test.py'" # Alternative way
  [####################################]  100%

~
❯ sqlite3 test.sqlar "SELECT hex(data) FROM sqlar WHERE name = 'test.py';" | python3 -c "import sys, zlib; sys.stdout.buffer.write(zlib.decompress(bytes.fromhex(sys.stdin.read())))"
import os

class Example:
    def __init__(self, arg1, arg2):
        self.arg1 = arg1

~
❯ rm test.py

~
❯ sqlar -l test.sqlar
test.py

~
❯ sqlar -x test.sqlar

~
❯ cat test.py
import os

class Example:
    def __init__(self, arg1, arg2):
        self.arg1 = arg1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the insert-files and convert CLI commands used in the example, including the -c field mappings and Python expressions. Reproduce the two-command sqlar workflow, then make the equivalent field conversion possible through insert-files and verify that the resulting data column can be decompressed back to the original file contents.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sqlite
Domain
cli, databases
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.