From 5811525c645612000960faafc5b995beac6983eb Mon Sep 17 00:00:00 2001 From: Alex Stevenson Date: Fri, 1 Aug 2025 19:24:59 -0400 Subject: [PATCH] Doing packages wrong... --- local/.records.go.swp | Bin 0 -> 1024 bytes local/go.mod | 3 ++ local/records.go | 89 ++++++++++++++++++++++++++++++++++++++++++ main.go | 20 ++++++---- rpgqui.db | Bin 16384 -> 16384 bytes 5 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 local/.records.go.swp create mode 100644 local/go.mod create mode 100644 local/records.go diff --git a/local/.records.go.swp b/local/.records.go.swp new file mode 100644 index 0000000000000000000000000000000000000000..63bee61d1eefe6da10c63e1f94581992d0a32646 GIT binary patch literal 1024 zcmYc?$V<%2S1{8vVn6|j9~c=Db5bi%1aWZkDsyqjpbF>YCnx6U7o{fW7o`;IrRSr{ Oj`BuBU^E2i9RdJTw+(dw literal 0 HcmV?d00001 diff --git a/local/go.mod b/local/go.mod new file mode 100644 index 0000000..9a3e15b --- /dev/null +++ b/local/go.mod @@ -0,0 +1,3 @@ +module git.rdx4.com/monqui/records + +go 1.18 diff --git a/local/records.go b/local/records.go new file mode 100644 index 0000000..c0a34c0 --- /dev/null +++ b/local/records.go @@ -0,0 +1,89 @@ +package records + +// User record management stuff. Eventually want to abstract +// this out to store any sort of record... +type User struct { + id int64 + name string +} + +func CreateUser(db *sql.DB, name string) (User) { + s := prep_query(db, "INSERT INTO users (name) VALUES (?)") + res, err := s.Exec(name) + check(err) + + var u User + + id, _ := res.LastInsertId() + u.id = id + u.name = name + + return u +} + +func GetUser(db *sql.DB, name string) (User) { + s := prep_query(db, "SELECT * FROM users WHERE name = ? LIMIT 1") + res, err := s.Query(name) + + check(err) + + var u User + + res.Next() + res.Scan(&u.id, &u.name) + res.Close() + + if u.id == 0 { + return create_user(db, name) + } else { + return u + } +} + +// Blerk. Start here with a get/create and see where +// that goes... +type Entity struct { + id int64 + user_id int64 + name string + spawn_line string +} + +func CreateEntity(db *sql.DB, user_id int64, name string, spawn_line string) (Entity) { + s := prep_query(db, "INSERT INTO entities (user_id, name, spawn_line) VALUES (?, ?, ?)") + res, err := s.Exec(user_id, name, spawn_line) + check(err) + + var ent Entity + + id, _ := res.LastInsertId() + ent.id = id + ent.user_id = user_id + ent.name = name + ent.spawn_line = spawn_line + + return ent +} + +func GetEntity(db *sql.DB, id int64) (Entity) { + s := prep_query(db, "SELECT * FROM entities WHERE id = ? LIMIT 1") + res, err := s.Query(id) + + check(err) + + var ent Entity + + res.Next() + err = res.Scan(&ent.id, &ent.user_id, &ent.name, &ent.spawn_line) + check(err) + + res.Close() + + + if ent.id == 0 { + log.Printf("Entity id %d doesn't exist!", id) + } + + return ent +} + diff --git a/main.go b/main.go index dd81aaa..a76ccb9 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,8 @@ import ( "strings" "os" + "./local/git.rdx4.com/monqui/records" + "database/sql" _ "github.com/mattn/go-sqlite3" ) @@ -68,12 +70,13 @@ func get_user(db *sql.DB, name string) (User) { type Entity struct { id int64 user_id int64 + name string spawn_line string } -func create_entity(db *sql.DB, user_id int64, spawn_line string) (Entity) { - s := prep_query(db, "INSERT INTO entities (user_id, spawn_line) VALUES (?, ?)") - res, err := s.Exec(user_id, spawn_line) +func create_entity(db *sql.DB, user_id int64, name string, spawn_line string) (Entity) { + s := prep_query(db, "INSERT INTO entities (user_id, name, spawn_line) VALUES (?, ?, ?)") + res, err := s.Exec(user_id, name, spawn_line) check(err) var ent Entity @@ -81,6 +84,7 @@ func create_entity(db *sql.DB, user_id int64, spawn_line string) (Entity) { id, _ := res.LastInsertId() ent.id = id ent.user_id = user_id + ent.name = name ent.spawn_line = spawn_line return ent @@ -95,9 +99,9 @@ func get_entity(db *sql.DB, id int64) (Entity) { var ent Entity res.Next() - res.Scan(&ent.id, &ent.user_id, &ent.spawn_line) -log.Println("WHY DOESN'T THIS WORK") -log.Printf("ID: %d, user_id: %d, spawn_line: %s", ent.id, ent.user_id, ent.spawn_line) + err = res.Scan(&ent.id, &ent.user_id, &ent.name, &ent.spawn_line) + check(err) + res.Close() @@ -136,9 +140,9 @@ log.Printf("ID: %d, name: %s", u.id, u.name) // make some entities... log.Println("Adding entities...\n") - e := create_entity(db, u.id, "hello im monqui") + e := create_entity(db, u.id, "idk a demon", "hello im monqui") log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line) - e = create_entity(db, u.id, "here's a whole nother line!") + e = create_entity(db, u.id, "idk a monster", "here's a whole nother line!") log.Printf("ID: %d, user_id: %d, spawn_line: %s", e.id, e.user_id, e.spawn_line) log.Println("Trying to fetch some entities...\n") diff --git a/rpgqui.db b/rpgqui.db index b4e9701626dcfab88edb17897a663f35f56b40bd..ea2014e9fc84fd99ab0ece2e84f669865c176e8d 100644 GIT binary patch delta 110 zcmZo@U~Fh$oFFaumVtqR1&E=5QE8%%G2`2f3Cr}kHZbtt=idO7VBRb!uz+7gmx+~u yQ{6c;C0ij;AvZs-xFoe`@_Bn{MR`V`gt9h7A|(|lm64j0ldq7O3sP2Cnh5}!i5(~a delta 108 zcmZo@U~Fh$oFFZ@mVtqR1&E=5k!hliG2_~e3Cr}kPB8Gl;y(eDVBRb!u!G-1fr*uY zlfgM7wJ24+SRqlNJR?6RRUt3G1Sq1AlbM&QD8dL*p`DSMlasHInX8bSpI2C#2>?G) B8;Sq`