Most active commenters

    ←back to thread

    115 points graderjs | 11 comments | | HN request time: 0.604s | source | bottom
    1. codenesium ◴[] No.25004913[source]
    Is sqlite not diffable?
    replies(3): >>25005043 #>>25005217 #>>25005391 #
    2. jitl ◴[] No.25005043[source]
    SQLite database files themselves are binary, which typically isn't diff-able with standard tools, so (eg) git wouldn't show you anything useful unless you configure a special tool for diffing sqlite files.

    And in fact, there is a sqlitediff.exe tool for diffing sqlite databases: https://sqlite.org/sqldiff.html

    But, it would still be a bummer to store them in git because git won't efficiently track changes between sqlite databases, it'll just add the whole binary blob on every commit. oof.

    replies(1): >>25005799 #
    3. Jakob ◴[] No.25005217[source]
    I would export the DB and use that for your diff/version control:

      sqlite3 yourdb.sqlite .dump
    
    If you really want to track the binary e.g. inside git, but still see textual diffs you would put that into your .gitconfig:

      [diff "sqlite3"]
        textconv = sqlite3 $1 .dump
    replies(1): >>25005630 #
    4. simonw ◴[] No.25005391[source]
    I wrote a tool that dumps a SQLite database out to disk as diffable JSON, precisely so you can easily record changes made to the database over time: https://github.com/simonw/sqlite-diffable

    I have a demo of it running against my blog's database here: https://github.com/simonw/simonwillisonblog-backup

    replies(1): >>25005974 #
    5. djeiasbsbo ◴[] No.25005630[source]
    To expand on this, you can now even export to markdown and basically have a nice overview of the database. I use this in my notes which are all written in markdown because markdown tables are painful to organise per hand.
    6. framecowbird ◴[] No.25005799[source]
    This might be a silly question, but is there a reason why git can't also diff binary files? If I have a huge binary file and I change a few bytes in the middle, what's stopping Git just checking that in as a diff? I don't see what's so special about text...

    [edit] just did some research and it looks like Git will store the delta of a binary file in its packfiles, just like a text file. The question is just how delta-able sqlite binary files are.

    replies(3): >>25005829 #>>25006385 #>>25006508 #
    7. graderjs ◴[] No.25005829{3}[source]
    I know Drew from Dropbox implemented a binary diff for his first version (on a bus) but I don't know the details. I don't know if git can somehow...but I suppose you could always MIME encode it (like email base64 encoding).
    8. jlelse ◴[] No.25005974[source]
    Thanks for this! I am trying to integrate something similar into my custom CMS.
    9. GordonS ◴[] No.25006385{3}[source]
    Diffing is about more than just efficient storage though, it's also about showing a history of human-readable changes (which obv you don't get with a binary format).
    replies(1): >>25012651 #
    10. andrewshadura ◴[] No.25006508{3}[source]
    AFAIR Sqlite files are normally in append mode.
    11. graderjs ◴[] No.25012651{4}[source]
    That's a good point, thank you