Skip to content

Commit 00644a1

Browse files
committed
feat: support a preview command
1 parent 9488f51 commit 00644a1

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Diff for: flake.nix

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
(pkgs.lib.hasSuffix "\.css" path) ||
3434
(pkgs.lib.hasSuffix "\.js" path) ||
3535
(pkgs.lib.hasSuffix "\.svg" path) ||
36+
(pkgs.lib.hasSuffix "\.sqlite3" path) ||
3637
(craneLib.filterCargoSources path type)
3738
;
3839
};
@@ -55,10 +56,19 @@
5556
cp -pr --reflink=auto -- ${ui} ui/dist
5657
'';
5758
});
59+
60+
docker = pkgs.dockerTools.buildLayeredImage {
61+
name = "sqlite-studio";
62+
tag = "latest";
63+
created = "now";
64+
config.Cmd = [ "${bin}/bin/sqlite-studio" "preview" "--address=0.0.0.0:3030" ];
65+
config.Expose = "3030";
66+
};
5867
in
5968
{
6069
packages = {
6170
default = bin;
71+
docker = docker;
6272
};
6373

6474
devShells.default = pkgs.mkShell {

Diff for: sample.sqlite3

864 KB
Binary file not shown.

Diff for: src/main.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use tokio_rusqlite::{Connection, OpenFlags};
66
use warp::Filter;
77

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

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

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

3234
let args = Args::parse();
33-
let db = TheDB::open(args.database).await?;
35+
let db = if args.database == "preview" {
36+
tokio::fs::write("sample.db", SAMPLE_DB).await?;
37+
TheDB::open("sample.db".to_string()).await?
38+
} else {
39+
TheDB::open(args.database).await?
40+
};
3441

3542
let cors = warp::cors()
3643
.allow_any_origin()

0 commit comments

Comments
 (0)