aboutsummaryrefslogtreecommitdiff
path: root/server/database
diff options
context:
space:
mode:
authorMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-04-28 10:12:46 +0530
committerMikunoNaka <bokuwakanojogahoshii@yahoo.com>2021-04-28 10:12:46 +0530
commit60f5d0cf22adc77b236f6c5a6e6aa2c7ff39ed77 (patch)
tree95b1902b7613fb9b1a7469499655fcfad8210aba /server/database
parent8187f8db90c5d301f9a8304fc954588167833695 (diff)
implemented a small package to get items from sqlite db
Diffstat (limited to 'server/database')
-rw-r--r--server/database/database.go44
1 files changed, 38 insertions, 6 deletions
diff --git a/server/database/database.go b/server/database/database.go
index 3e60311..16b6f65 100644
--- a/server/database/database.go
+++ b/server/database/database.go
@@ -6,17 +6,49 @@
* Copyright (c) 2021 Vidhu Kant Sharma
*/
-// Idk how databases work
-// this package is supposed to handle the sqlite database
+// Idk how databases work this package is supposed to handle the sqlite database
// will figure that out
package database
import (
- "fmt"
+ _ "github.com/mattn/go-sqlite3"
+ "database/sql"
)
-// very important function that fucking needed a new package
-func SayHello() {
- fmt.Println("Hello")
+type Item struct {
+ Model string
+ Desc string `json:"Description"`
+ Price int // *float32
+ HSN int
+}
+
+
+var myDatabase *sql.DB
+func init() {
+ myDatabase, _ = sql.Open("sqlite3", "./openbills.db")
+}
+
+var myItems *sql.Stmt
+var addToMyItems *sql.Stmt
+func init() {
+ myItems, _ = myDatabase.Prepare("CREATE TABLE IF NOT EXISTS RegisteredItems (id INTEGER PRIMARY KEY, model TEXT, desc TEXT, price INTEGER, HSN INTEGER)")
+ myItems.Exec()
+
+ addToMyItems, _ = myDatabase.Prepare("INSERT INTO RegisteredItems (id, model, desc, price, hsn) VALUES (?, ?, ?, ?, ?)")
+}
+
+func GetAllItems() []Item {
+ var allItems []Item
+ rows, _ := myDatabase.Query("SELECT model, desc, price, hsn FROM RegisteredItems")
+
+ var model string
+ var desc string
+ var price int
+ var hsn int
+ for rows.Next() {
+ rows.Scan(&model, &desc, &price, &hsn)
+ allItems = append(allItems, Item{model, desc, price, hsn})
+ }
+ return allItems
}