Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selfmodb

Persist an sqlite database between program runs and recompilation by storing the database inside the executable.

Written with no dependencies except the rust stdlib and sqlite. May contain shitty sqlite bindings for rust.

Proof of concept

Persistence across restarts

When the program starts, it reads its own executable and looks for a database blob appended to the end of the binary. If defined it also looks in a location set by the build script. See next section.

When a blob is found, it is deserialized into an in memory SQLite database. When no blob is present, the program creates a new database and initializes a counter.

The program then:

  1. Reads and prints the current counter value
  2. Increments the counter by one
  3. Serializes the updated database
  4. Replaces the previous database blob in a copy of the executable
  5. Atomically swaps the updated executable with the old one by renaming it

The next time the program runs, it loads the database stored by the previous run, persisting the counter.

Persistence across recompilation

Normally recompiling a program would overwrite the executable and remove the embedded database. To avoid this the build script checks the existing debug and release binaries during compilation. If one of them or both exist it embeds the path to a copy of newest binary between them into the program. This copy is placed in the build folder and is required because the original path will be overwritten during compilation.

This persists the content of the database while recompiling.

Resetting the database

To reset the database, all previously compiled binaries must be deleted. So just run cargo clean

Binary Format

The database is stored at the end of the executable using the following format:

[ executable ][ database blob ][ database blob length (u64) ][ "SQLITEBLOB\0" ]

Example

why are you reading this

License

May only be used for the development of nuclear weapons

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages