First working query of store_uuid

This commit is contained in:
Jacob Hinkle 2022-10-14 12:53:33 -04:00
parent dc2edcf0a3
commit afb2fae01b
6 changed files with 126 additions and 45 deletions

43
Cargo.lock generated
View File

@ -28,6 +28,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -133,6 +139,7 @@ dependencies = [
"clap", "clap",
"env_logger", "env_logger",
"log", "log",
"sqlite",
] ]
[[package]] [[package]]
@ -147,6 +154,12 @@ version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "pkg-config"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@ -206,6 +219,36 @@ version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "sqlite"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2df8edd55685048550daaaf2be9024182f3523086cc86f7d50c136e55173e8c"
dependencies = [
"libc",
"sqlite3-sys",
]
[[package]]
name = "sqlite3-src"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1815a7a02c996eb8e5c64f61fcb6fd9b12e593ce265c512c5853b2513635691"
dependencies = [
"cc",
"pkg-config",
]
[[package]]
name = "sqlite3-sys"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d47c99824fc55360ba00caf28de0b8a0458369b832e016a64c13af0ad9fbb9ee"
dependencies = [
"libc",
"sqlite3-src",
]
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"

View File

@ -21,3 +21,4 @@ path = "src/cli/main.rs"
clap = { version = "4.0.14", features = ["derive"] } clap = { version = "4.0.14", features = ["derive"] }
env_logger = "0.9.1" env_logger = "0.9.1"
log = "0.4.17" log = "0.4.17"
sqlite = "0.27.0"

47
flake.lock generated
View File

@ -1,45 +1,28 @@
{ {
"nodes": { "nodes": {
"naersk": { "crate2nix": {
"inputs": { "flake": false,
"nixpkgs": "nixpkgs"
},
"locked": { "locked": {
"lastModified": 1662220400, "lastModified": 1665362239,
"narHash": "sha256-9o2OGQqu4xyLZP9K6kNe1pTHnyPz0Wr3raGYnr9AIgY=", "narHash": "sha256-vNMu88WotPaOfuzubfOsLcaHB9WwDfV5/drEzY8tpFo=",
"owner": "nix-community", "owner": "kolloch",
"repo": "naersk", "repo": "crate2nix",
"rev": "6944160c19cb591eb85bbf9b2f2768a935623ed3", "rev": "cdcdd4950cc6ef1133b5f866a7c20dc06c130a84",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-community", "owner": "kolloch",
"ref": "master", "repo": "crate2nix",
"repo": "naersk",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1664266718, "lastModified": 1653936696,
"narHash": "sha256-j2okM1ghRbJY1Akxpu/pkuxIvT9FSycLwUxAYUOr6PI=", "narHash": "sha256-M6bJShji9AIDZ7Kh7CPwPBPb/T7RiVev2PAcOi4fxDQ=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2e977bf954e84a981b15ff4d2442802ce9b675f9", "rev": "ce6aa13369b667ac2542593170993504932eb836",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1665634984,
"narHash": "sha256-zwXeMc96BD9iFxSB/SLr3dI8iYpqM+seX9qy6bGV+cw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cfea568da97a2668ef3cb3fc42eaacfb0e706807",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -51,8 +34,8 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"naersk": "naersk", "crate2nix": "crate2nix",
"nixpkgs": "nixpkgs_2", "nixpkgs": "nixpkgs",
"utils": "utils" "utils": "utils"
} }
}, },

View File

@ -1,21 +1,39 @@
{ {
inputs = { inputs = {
naersk.url = "github:nix-community/naersk/master"; #naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils"; utils.url = "github:numtide/flake-utils";
crate2nix = {
url = "github:kolloch/crate2nix";
flake = false;
};
}; };
outputs = { self, nixpkgs, utils, naersk }: outputs = { self, nixpkgs, utils, crate2nix }:
utils.lib.eachDefaultSystem (system: utils.lib.eachDefaultSystem (system:
let let
crateName = "nancy";
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
naersk-lib = pkgs.callPackage naersk { }; inherit (import "${crate2nix}/tools.nix" { inherit pkgs; })
generatedCargoNix;
#naersk-lib = pkgs.callPackage naersk { };
project = import (generatedCargoNix {
name = crateName;
src = ./.;
}) {
inherit pkgs;
defaultCrateOverrides = pkgs.defaultCrateOverrides // {
# Crate dependency overrides go here
};
};
in in
{ {
defaultPackage = naersk-lib.buildPackage ./.; packages.${crateName} = project.rootCrate.build;
defaultPackage = self.packages.${system}.${crateName};
#defaultPackage = naersk-lib.buildPackage ./.;
devShell = with pkgs; mkShell { devShell = with pkgs; mkShell {
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ]; inputsFrom = builtins.attrValues self.packages.${system};
RUST_SRC_PATH = rustPlatform.rustLibSrc; buildInputs = [ cargo rust-analyzer clippy rustfmt ];
}; };
}); });
} }

View File

@ -13,11 +13,9 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum Commands { enum Commands {
/// Record changes to a store directory (or a new store) /// Record changes to a store directory (or a new store)
Record { Record {},
},
/// Check for changes in store and print basic statistics /// Check for changes in store and print basic statistics
Status { Status {},
},
/// Just say hello /// Just say hello
Hello { Hello {
#[arg(short, long)] #[arg(short, long)]
@ -36,10 +34,10 @@ fn main() {
nancy::say_hello(); nancy::say_hello();
} }
} }
Some(Commands::Record { }) => { Some(Commands::Record {}) => {
println!("Record not yet implemented"); println!("Record not yet implemented");
} }
Some(Commands::Status { }) => { Some(Commands::Status {}) => {
println!("Status not yet implemented"); println!("Status not yet implemented");
} }
None => {} None => {}

View File

@ -1,9 +1,47 @@
use log; use log;
use sqlite;
mod store; pub struct Store<'a> {
conn: &'a sqlite::Connection,
uuid: &'a str,
}
#[derive(Debug)]
pub enum DBError {
NoRowsReturned,
NoneValue,
}
pub fn get_uuid(conn: &sqlite::Connection) -> Result<String, DBError> {
let mut uuid = Err(DBError::NoRowsReturned);
conn.iterate(
"
SELECT value FROM local_metadata WHERE key = 'store_uuid';
",
|pairs| {
uuid = match (*pairs)[0].1 {
Some(u) => Ok(u.to_string()),
None => Err(DBError::NoneValue),
};
false // only process the first row
},
);
uuid
}
pub fn say_hello() { pub fn say_hello() {
log::trace!("enter say_hello()"); log::trace!("enter say_hello()");
println!("If you see nothing in the next line, set RUST_LOG to info or lower"); println!("If you see nothing in the next line, set RUST_LOG to info or lower");
log::info!("Hello from libnancy.rlib!!!"); log::info!("Hello from libnancy.rlib!!!");
let store_path = "nancy.db";
let conn = sqlite::open(store_path).unwrap();
let uuid = get_uuid(&conn).unwrap();
let this_store = Store {
conn: &conn,
uuid: &uuid,
};
println!("Store UUID: {}", this_store.uuid);
} }