-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix merge conflicts with main when adding LLM functionality
- Loading branch information
Showing
13 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,5 @@ Cargo.lock | |
|
||
backend/target/ | ||
|
||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Setup | ||
1. Install Rust | ||
2. cargo build | ||
3. echo DATABASE_URL=postgres://username:password@localhost/diesel_demo > .env | ||
4. diesel setup | ||
5. cargo run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use crate::kube::{KubeId, Kube}; | ||
use std::vec::Vec; | ||
|
||
pub struct Recipe { | ||
items: Vec<KubeId>, | ||
} | ||
|
||
impl Recipe { | ||
pub fn new(items: Vec<KubeId>) -> Self { | ||
let mut items = items; | ||
items.sort(); | ||
Recipe { items } | ||
} | ||
pub fn hash(&self) -> u64 { | ||
let big_key = self.items.iter().fold(0, |acc, x| acc ^ x.as_u128()); | ||
(big_key >> 64 & big_key) as u64 | ||
} | ||
} | ||
|
||
pub struct PsqlCache { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
// Note this useful idiom: importing names from outer (for mod tests) scope. | ||
use super::*; | ||
|
||
#[test] | ||
|
||
fn test_kube_cache_hash_is_not_order_sensitive() { | ||
let mut items = vec![]; | ||
items.push(KubeId::new("a")); | ||
items.push(KubeId::new("b")); | ||
items.push(KubeId::new("b")); | ||
items.push(KubeId::new("c")); | ||
let recipe1 = Recipe::new(items.clone()); | ||
|
||
items.reverse(); | ||
let recipe2 = Recipe::new(items.clone()); | ||
assert_eq!(recipe1.hash(), recipe2.hash()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
use uuid::Uuid; | ||
|
||
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] | ||
pub struct KubeId { | ||
uuid: Uuid, | ||
} | ||
|
||
impl KubeId { | ||
pub fn new(name: &str) -> Self { | ||
let mut name = name.to_string(); | ||
name.push_str("kube"); | ||
KubeId { | ||
uuid: Uuid::new_v5(&Uuid::NAMESPACE_DNS, name.as_bytes()), | ||
} | ||
} | ||
|
||
pub fn as_u128(&self) -> u128 { | ||
self.uuid.as_u128() | ||
} | ||
} | ||
|
||
#[derive(PartialEq, Debug)] | ||
pub struct Kube { | ||
pub uuid: uuid::Uuid, | ||
pub id: KubeId, | ||
pub name: String, | ||
} | ||
impl Kube { | ||
pub fn new(name: String) -> Kube { | ||
Kube { | ||
id: KubeId::new(name.as_str()), | ||
name, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ pub mod space; | |
pub mod kube; | ||
pub mod player; | ||
pub mod llm; | ||
pub mod cache; | ||
|
||
type Coordinate = [u64; 2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- This file was automatically created by Diesel to setup helper functions | ||
-- and other internal bookkeeping. This file is safe to edit, any future | ||
-- changes will be added to existing projects as new migrations. | ||
|
||
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); | ||
DROP FUNCTION IF EXISTS diesel_set_updated_at(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- This file was automatically created by Diesel to setup helper functions | ||
-- and other internal bookkeeping. This file is safe to edit, any future | ||
-- changes will be added to existing projects as new migrations. | ||
|
||
|
||
|
||
|
||
-- Sets up a trigger for the given table to automatically set a column called | ||
-- `updated_at` whenever the row is modified (unless `updated_at` was included | ||
-- in the modified columns) | ||
-- | ||
-- # Example | ||
-- | ||
-- ```sql | ||
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); | ||
-- | ||
-- SELECT diesel_manage_updated_at('users'); | ||
-- ``` | ||
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ | ||
BEGIN | ||
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s | ||
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ | ||
BEGIN | ||
IF ( | ||
NEW IS DISTINCT FROM OLD AND | ||
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at | ||
) THEN | ||
NEW.updated_at := current_timestamp; | ||
END IF; | ||
RETURN NEW; | ||
END; | ||
$$ LANGUAGE plpgsql; |