Init Database Methods

This commit is contained in:
Hoernschen 2020-09-30 10:28:49 +02:00
parent a39f23411b
commit 126070829c
11 changed files with 173 additions and 91 deletions

View file

@ -1,19 +1,5 @@
package device package device
import "database/sql" func New() device *Device {
func createDevice(db *sql.DB) { }
}
func readDevice(db *sql.DB) {
}
func updateDevice(db *sql.DB) {
}
func deleteDevice(db *sql.DB) {
}

View file

@ -1,21 +1,5 @@
package event package event
import ( func New() event *Event {
"database/sql"
) }
func createEvent(db *sql.DB) {
}
func readEvent(db *sql.DB) {
}
func updateEvent(db *sql.DB) {
}
func deleteEvent(db *sql.DB) {
}

View file

@ -1,19 +1,5 @@
package room package room
import "database/sql" func New() room *Room {
func createRoom(db *sql.DB) { }
}
func readRoom(db *sql.DB) {
}
func updateRoom(db *sql.DB) {
}
func deleteRoom(db *sql.DB) {
}

View file

@ -1,19 +1,5 @@
package transaction package transaction
import "database/sql" func New() transaction *Transaction {
func createTransaction(db *sql.DB) { }
}
func readTransaction(db *sql.DB) {
}
func updateTransaction(db *sql.DB) {
}
func deleteTransaction(db *sql.DB) {
}

View file

@ -1,19 +1,5 @@
package user package user
import "database/sql" func New() user *User {
func createUser(db *sql.DB) { }
}
func readUser(db *sql.DB) {
}
func updateUser(db *sql.DB) {
}
func deleteUser(db *sql.DB) {
}

View file

@ -1,4 +1,4 @@
package utils package database
import ( import (
"database/sql" "database/sql"
@ -17,13 +17,22 @@ func InitDB(filepath string) *sql.DB {
panic("DB couldn't be initialized") panic("DB couldn't be initialized")
} }
// TODO: Change to correct DB-Structure handleError(initDeviceTable(db))
statement, _ := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)") handleError(initEventTable(db))
statement.Exec() handleError(initRoomTable(db))
handleError(initTransactionTable(db))
handleError(initUserTable(db))
return db return db
} }
func handleError(err error) {
if err != nil {
// TODO: Add Error Message
panic("Could not execute Database Query")
}
}
/* /*
sqlStmt := fmt.Sprintf(`INSERT INTO data sqlStmt := fmt.Sprintf(`INSERT INTO data
(id, content) (id, content)

View file

@ -0,0 +1,29 @@
package device
import (
"database/sql"
"nutfactory.org/Matrix/entities/device"
)
func initDeviceTable(db *sql.DB) err error {
// TODO: Change to correct Table-Structure
statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
}
func createDevice(db *sql.DB, device *Device) err error {
}
func readDevice(db *sql.DB, id string) (device *Device, err error) {
}
func updateDevice(db *sql.DB, device *Device) err error {
}
func deleteDevice(db *sql.DB, id string) err error {
}

View file

@ -0,0 +1,29 @@
package event
import (
"database/sql"
"nutfactory.org/Matrix/entities/event"
)
func initEventTable(db *sql.DB) err error {
// TODO: Change to correct Table-Structure
statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
}
func createEvent(db *sql.DB, event *Event) err error {
}
func readEvent(db *sql.DB, id string) (event *Event, err error) {
}
func updateEvent(db *sql.DB, event *Event) err error {
}
func deleteEvent(db *sql.DB, id string) err error {
}

View file

@ -0,0 +1,29 @@
package room
import (
"database/sql"
"nutfactory.org/Matrix/entities/room"
)
func initRoomTable(db *sql.DB) err error {
// TODO: Change to correct Table-Structure
statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
}
func createRoom(db *sql.DB, room *Room) err error {
}
func readRoom(db *sql.DB, id string) (room *Room, err error) {
}
func updateRoom(db *sql.DB, room *Room) err error {
}
func deleteRoom(db *sql.DB, id string) err error {
}

View file

@ -0,0 +1,29 @@
package transaction
import (
"database/sql"
"nutfactory.org/Matrix/entities/transaction"
)
func initTransactionTable(db *sql.DB) err error {
// TODO: Change to correct Table-Structure
statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
}
func createTransaction(db *sql.DB, transaction *Transaction) err error {
}
func readTransaction(db *sql.DB, id string) (transaction *Transaction, err error) {
}
func updateTransaction(db *sql.DB, transaction *Transaction) err error {
}
func deleteTransaction(db *sql.DB, id string) err error {
}

View file

@ -0,0 +1,29 @@
package user
import (
"database/sql"
"nutfactory.org/Matrix/entities/user"
)
func initUserTable(db *sql.DB) err error {
// TODO: Change to correct Table-Structure
statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)")
statement.Exec()
}
func createUser(db *sql.DB, user *User) err error {
}
func readUser(db *sql.DB id string) (user *User, err error) {
}
func updateUser(db *sql.DB, user *User) err error {
}
func deleteUser(db *sql.DB, id string) err error {
}