Skip to content

Commit

Permalink
feat: support a preview command
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 16, 2024
1 parent 9488f51 commit 00644a1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
(pkgs.lib.hasSuffix "\.css" path) ||
(pkgs.lib.hasSuffix "\.js" path) ||
(pkgs.lib.hasSuffix "\.svg" path) ||
(pkgs.lib.hasSuffix "\.sqlite3" path) ||
(craneLib.filterCargoSources path type)
;
};
Expand All @@ -55,10 +56,19 @@
cp -pr --reflink=auto -- ${ui} ui/dist
'';
});

docker = pkgs.dockerTools.buildLayeredImage {
name = "sqlite-studio";
tag = "latest";
created = "now";
config.Cmd = [ "${bin}/bin/sqlite-studio" "preview" "--address=0.0.0.0:3030" ];
config.Expose = "3030";
};
in
{
packages = {
default = bin;
docker = docker;
};

devShells.default = pkgs.mkShell {
Expand Down
Binary file added sample.sqlite3
Binary file not shown.
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ use tokio_rusqlite::{Connection, OpenFlags};
use warp::Filter;

const ROWS_PER_PAGE: i32 = 50;
const SAMPLE_DB: &[u8] = include_bytes!("../sample.sqlite3");

/// Web based SQLite database browser.
#[derive(Parser, Debug)]
struct Args {
/// Path to the sqlite database file.
/// Path to the sqlite database file. [use the path "preview" if you don't have an sqlite db at
/// hand, a sample db will be created for you]
database: String,

/// The address to bind to.
Expand All @@ -30,7 +32,12 @@ async fn main() -> color_eyre::Result<()> {
.init();

let args = Args::parse();
let db = TheDB::open(args.database).await?;
let db = if args.database == "preview" {
tokio::fs::write("sample.db", SAMPLE_DB).await?;
TheDB::open("sample.db".to_string()).await?
} else {
TheDB::open(args.database).await?
};

let cors = warp::cors()
.allow_any_origin()
Expand Down

0 comments on commit 00644a1

Please sign in to comment.