From 0c8bd064e3875fb0f0b6b1b09d22318b622dc95d Mon Sep 17 00:00:00 2001 From: Alex Stevenson Date: Fri, 25 Jul 2025 19:14:06 -0400 Subject: [PATCH 1/2] fixing tabs --- main.go | 27 +++++++++++++-------------- words.db | Bin 16384 -> 16384 bytes 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 1787bd1..46bce4d 100644 --- a/main.go +++ b/main.go @@ -5,16 +5,15 @@ import ( "log" _ "github.com/mattn/go-sqlite3" -) +) // Book is a placeholder for book type Word struct { - word_id int - source_id int - previous string + source_id int + previous string current string - next string - count int + next string + count int } type Source struct { @@ -60,14 +59,14 @@ func main() { FOREIGN KEY(source_id) REFERENCES sources(source_id) ); `).Exec() - log.Println("Done making tables!") + log.Println("Done making tables!") - log.Println("Making indexes...") - prep_query(db, "CREATE INDEX words_sources_index ON words(source_id)").Exec() - log.Println("Done making indexes!") + log.Println("Making indexes...") + prep_query(db, "CREATE INDEX words_sources_index ON words(source_id)").Exec() + log.Println("Done making indexes!") - log.Println("Inserting source/word...") - prep_query(db, ` + log.Println("Inserting source/word...") + prep_query(db, ` INSERT INTO sources (name) VALUES @@ -100,8 +99,8 @@ func main() { tempWord.word_id, tempWord.current, tempWord.next, tempWord.source_id) } - // Update - prep_query(db, "UPDATE sources SET name=? WHERE source_id=?").Exec("Monqu2", 1) + // Update + prep_query(db, "UPDATE sources SET name=? WHERE source_id=?").Exec("Monqu2", 1) rows, _ = db.Query("SELECT source_id, name FROM sources") for rows.Next() { diff --git a/words.db b/words.db index eca1ac204de93e47fb208bf90075635df4c3e6d2..c4730cf57e7fcaeae1edf314777c1630b4b63e6f 100644 GIT binary patch delta 37 kcmZo@U~Fh$oFFB{$jrdNzyicDuw2sr=% From a3fa5d6645d77f46fa192cd2be76f916f9e4174e Mon Sep 17 00:00:00 2001 From: Alex Stevenson Date: Sat, 26 Jul 2025 18:26:52 -0400 Subject: [PATCH 2/2] Cleaning up a bit and trying to rework stuff. Need to sort out initializing the DB better... --- main.go | 135 ++++++++++++++---------------------------- words.db => rpgqui.db | Bin 16384 -> 12288 bytes setup.sql | 15 +++++ 3 files changed, 59 insertions(+), 91 deletions(-) rename words.db => rpgqui.db (71%) create mode 100644 setup.sql diff --git a/main.go b/main.go index 46bce4d..5ec401e 100644 --- a/main.go +++ b/main.go @@ -3,22 +3,47 @@ package main import ( "database/sql" "log" + "os/exec" + // "reflect" _ "github.com/mattn/go-sqlite3" ) -// Book is a placeholder for book -type Word struct { - source_id int - previous string - current string - next string - count int +type active_record interface { + init(string, int) bool + create() bool + read() bool + update() bool + delete() bool } -type Source struct { - source_id int - name string +type ActiveSqliteRow struct { + id int + table_name string + columns []string +// values map[string] +} +/* +func (r ActiveSqliteRow) init(t string, i int) bool{ + log.Print("In init with" + t) + log.Print(i) + + r.id = i + r.table_name = t + + return true +} +*/ +type Entity struct { + id int + user_id int + name string + spawn_line string +} + +type User struct { + id int + name string } func prep_query(db *sql.DB, q string) (*sql.Stmt){ @@ -33,87 +58,15 @@ func prep_query(db *sql.DB, q string) (*sql.Stmt){ } func main() { - db, _ := sql.Open("sqlite3", "words.db") + // exec setup.sql to init + cmd := exec.Command("sqlite3", "rpgqui.db < sedfsftup.sql") + out, err := cmd.Output() - log.Println("Nuking tables...") - prep_query(db, "DROP TABLE IF EXISTS words").Exec() - prep_query(db, "DROP TABLE IF EXISTS sources").Exec() - log.Println("Done nuking tables!") + if err != nil { + log.Print(err) + } else { + log.Print(out) + } - log.Println("Creating tables...") - prep_query(db, ` - CREATE TABLE IF NOT EXISTS sources ( - source_id INTEGER PRIMARY KEY, - name VARCHAR(64) - ); - `).Exec() - - prep_query(db, ` - CREATE TABLE IF NOT EXISTS words ( - word_id INTEGER PRIMARY KEY, - source_id INTEGER, - previous VARCHAR(64) DEFAULT NULL, - current VARCHAR(64), - next VARCHAR(64) DEFAULT NULL, - count INTEGER DEFAULT 0, - FOREIGN KEY(source_id) REFERENCES sources(source_id) - ); - `).Exec() - log.Println("Done making tables!") - - log.Println("Making indexes...") - prep_query(db, "CREATE INDEX words_sources_index ON words(source_id)").Exec() - log.Println("Done making indexes!") - - log.Println("Inserting source/word...") - prep_query(db, ` - INSERT INTO sources - (name) - VALUES - (?) - `).Exec("Monqui") - - prep_query(db, ` - INSERT INTO words - (current, next, source_id) - VALUES - (?, ?, ?) - `).Exec("My", "name", 1) - - log.Println("Inserted the source/word into database!") - - rows, _ := db.Query("SELECT source_id, name FROM sources") - var tempSource Source - for rows.Next() { - rows.Scan(&tempSource.source_id, &tempSource.name) - log.Printf("source_id:%d, name:%s\n", - tempSource.source_id, tempSource.name) - } - - rows, _ = db.Query("SELECT word_id, current, next, source_id FROM words") - var tempWord Word - for rows.Next() { - rows.Scan(&tempWord.word_id, &tempWord.current, &tempWord.next, &tempWord.source_id) - log.Printf( - "word_id:%d, current:%s, next:%s, source_id:%d\n", - tempWord.word_id, tempWord.current, tempWord.next, tempWord.source_id) - } - - // Update - prep_query(db, "UPDATE sources SET name=? WHERE source_id=?").Exec("Monqu2", 1) - - rows, _ = db.Query("SELECT source_id, name FROM sources") - for rows.Next() { - rows.Scan(&tempSource.source_id, &tempSource.name) - log.Printf("source_id:%d, name:%s\n", - tempSource.source_id, tempSource.name) - } - - // -/* - // Delete - statement, _ = db.Prepare("delete from books where id=?") - statement.Exec(1) - log.Println("Successfully deleted the book in database!") -*/ +// db, _ := sql.Open("sqlite3", "words.db") } diff --git a/words.db b/rpgqui.db similarity index 71% rename from words.db rename to rpgqui.db index c4730cf57e7fcaeae1edf314777c1630b4b63e6f..1f6de18f65e865855709b400b42a368f95367bce 100644 GIT binary patch literal 12288 zcmeI#O-sWt7zgmAlMM>K+3#}oi z)2Ew5vuYh}*zvb{pg;fu5P$##AOHafKmY;|fB*#kL0~s+g> zZmmEHKNb}GS3^PdEV(w3o>5)GC>8@D>0X9+zMRmlnDk7r_#5$*lB8QiOx3*x9YN^+<}okRl4ixcpS+>X~PI&%EO} z4qrQELPc;^K3acLDW`t(*pWeb*2Yn6ueh6=OFs$(AOHafKmY;|fB*y_009U<00Mg~ ffcyU*|6HU70SG_<0uX=z1Rwwb2tWV=5U2#U_={aE literal 16384 zcmeI&O-sWt7zglV6=wyV9;Aqu=eUB1Z|K!JGaYtS;}kuO=_(Ag)o%6WsE9{DgkL9ZZO7%)Ti5C)Q{eK z-ktcpS2gCI>@gK!jE}Iw^Z1GC&>#Q-2tWV=5P$##AOHafK;RDrj*MYz$>MPfMNB^fL0VTVdQLI&@@d z%aO&EWt%oc**S1)rBi`_tH=AN`b#7g!Z^wQ+F^H<`D7>M z9VsfCp5AYd1W8dAQg|h?PZ@5{tg35Y^1L-O!|zuUsw^h!a(!IcU<#JrXtLkHg2sja z?Ob|A{cO$)Z%kci5P$##AOHafKmY;|fB*y_009ULl7OlHm!GbN!BxDNKL5Y6!s{R% z5NCk^1Rwwb2tWV=5P$##AOHaf{BwaZo@XYToEoX#>6ZdV6$dZ8Gj-|r{d50Z2gip1 a1Rwwb2tWV=5P$##AOHaf44i;rnC1r!`J@p5 diff --git a/setup.sql b/setup.sql new file mode 100644 index 0000000..08f6867 --- /dev/null +++ b/setup.sql @@ -0,0 +1,15 @@ +DROP TABLE IF EXISTS users; +DROP TABLE IF EXISTS entities; + +CREATE TABLE IF NOT EXISTS users ( + id INTEGER PRIMARY KEY, + name VARCHAR(64) +); + +CREATE TABLE IF NOT EXISTS entities ( + id INTEGER PRIMARY KEY, + user_id INTEGER, + name VARCHAR(64), + spawn_line VARCHAR(64), + FOREIGN KEY(user_id) REFERENCES users(id) +); \ No newline at end of file