Skip to content

Commit

Permalink
start rust project
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantm committed Aug 12, 2023
1 parent b297f32 commit b43e41f
Show file tree
Hide file tree
Showing 16 changed files with 332 additions and 0 deletions.
1 change: 1 addition & 0 deletions rust/.direnv/flake-profile
1 change: 1 addition & 0 deletions rust/.direnv/flake-profile-1-link
1 change: 1 addition & 0 deletions rust/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL=sqlite://db.sqlite
2 changes: 2 additions & 0 deletions rust/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake
dotenv
2 changes: 2 additions & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
db.sqlite
145 changes: 145 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "nixpkgs-update"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
diesel = { version = "2.1.0", features = ["sqlite"] }
9 changes: 9 additions & 0 deletions rust/diesel.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# For documentation on how to configure this file,
# see https://diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs"
custom_type_derives = ["diesel::query_builder::QueryId"]

[migrations_directory]
dir = "migrations"
25 changes: 25 additions & 0 deletions rust/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions rust/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
description = "update nixpkgs automatically";

outputs = { self, nixpkgs } @ args: let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShells.x86_64-linux.default = pkgs.mkShell {
packages = [
pkgs.cargo
pkgs.clippy
pkgs.sqlite
pkgs.diesel-cli
];
};
};
}
1 change: 1 addition & 0 deletions rust/migrations/2023-08-12-152848_create_packages/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP table packages;
27 changes: 27 additions & 0 deletions rust/migrations/2023-08-12-152848_create_packages/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE packages (
id text PRIMARY KEY NOT NULL
, attr_path text NOT NULL
, version_nixpkgs_master text
, version_nixpkgs_staging text
, version_nixpkgs_staging_next text
, version_repology text
, version_github text
, version_gitlab text
, version_pypi text
, project_repology text
, nixpkgs_name_replogy text
, owner_github text
, repo_github text
, owner_gitlab text
, repo_gitlab text
, last_checked_repology text
, last_checked_github text
, last_hecked_gitlab text
, last_hecked_pypi text
, last_checked_pending_pr text
, last_update_attempt text
, pending_pr integer
, pending_pr_owner text
, pending_pr_branch_name text
, last_update_log text
)
11 changes: 11 additions & 0 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub mod models;
pub mod schema;

use diesel::prelude::*;
use std::env;

pub fn establish_connection() -> SqliteConnection {
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
SqliteConnection::establish(&database_url)
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
}
18 changes: 18 additions & 0 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use nixpkgs_update::models::*;
use nixpkgs_update::*;
use diesel::prelude::*;

fn main() {
use nixpkgs_update::schema::packages::dsl::*;

let connection = &mut establish_connection();
let results : Vec<Package> =
packages.
load(connection)
.expect("Error loading packages");

println!("Displaying {} packages", results.len());
for package in results {
println!("{} {}", package.id, package.attr_path);
}
}
33 changes: 33 additions & 0 deletions rust/src/models.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use diesel::prelude::*;

#[derive(Queryable, Selectable)]
#[diesel(table_name = crate::schema::packages)]
#[diesel(check_for_backend(diesel::sqlite::Sqlite))]
pub struct Package {
pub id: String,
pub attr_path: String,
pub version_nixpkgs_master: Option<String>,
pub version_nixpkgs_staging: Option<String>,
pub version_nixpkgs_staging_next: Option<String>,
pub version_repology: Option<String>,
pub version_github: Option<String>,
pub version_gitlab: Option<String>,
pub version_pypi: Option<String>,
pub project_repology: Option<String>,
pub nixpkgs_name_replogy: Option<String>,
pub owner_github: Option<String>,
pub repo_github: Option<String>,
pub owner_gitlab: Option<String>,
pub repo_gitlab: Option<String>,
pub last_checked_repology: Option<String>,
pub last_checked_github: Option<String>,
pub last_hecked_gitlab: Option<String>,
pub last_hecked_pypi: Option<String>,
pub last_checked_pending_pr: Option<String>,
pub last_update_attempt: Option<String>,
pub pending_pr: Option<i32>,
pub pending_pr_owner: Option<String>,
pub pending_pr_branch_name: Option<String>,
pub last_update_log: Option<String>,

}
31 changes: 31 additions & 0 deletions rust/src/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// @generated automatically by Diesel CLI.

diesel::table! {
packages (id) {
id -> Text,
attr_path -> Text,
version_nixpkgs_master -> Nullable<Text>,
version_nixpkgs_staging -> Nullable<Text>,
version_nixpkgs_staging_next -> Nullable<Text>,
version_repology -> Nullable<Text>,
version_github -> Nullable<Text>,
version_gitlab -> Nullable<Text>,
version_pypi -> Nullable<Text>,
project_repology -> Nullable<Text>,
nixpkgs_name_replogy -> Nullable<Text>,
owner_github -> Nullable<Text>,
repo_github -> Nullable<Text>,
owner_gitlab -> Nullable<Text>,
repo_gitlab -> Nullable<Text>,
last_checked_repology -> Nullable<Text>,
last_checked_github -> Nullable<Text>,
last_hecked_gitlab -> Nullable<Text>,
last_hecked_pypi -> Nullable<Text>,
last_checked_pending_pr -> Nullable<Text>,
last_update_attempt -> Nullable<Text>,
pending_pr -> Nullable<Integer>,
pending_pr_owner -> Nullable<Text>,
pending_pr_branch_name -> Nullable<Text>,
last_update_log -> Nullable<Text>,
}
}

0 comments on commit b43e41f

Please sign in to comment.