diff --git a/entities/device/deviceController.go b/entities/device/deviceController.go index 6d85b83..9a04ad0 100644 --- a/entities/device/deviceController.go +++ b/entities/device/deviceController.go @@ -1,19 +1,5 @@ package device -import "database/sql" - -func createDevice(db *sql.DB) { - -} - -func readDevice(db *sql.DB) { - -} - -func updateDevice(db *sql.DB) { - -} - -func deleteDevice(db *sql.DB) { - -} +func New() device *Device { + +} \ No newline at end of file diff --git a/entities/event/eventController.go b/entities/event/eventController.go index 341d5f6..8a315f1 100644 --- a/entities/event/eventController.go +++ b/entities/event/eventController.go @@ -1,21 +1,5 @@ package event -import ( - "database/sql" -) - -func createEvent(db *sql.DB) { - -} - -func readEvent(db *sql.DB) { - -} - -func updateEvent(db *sql.DB) { - -} - -func deleteEvent(db *sql.DB) { - -} +func New() event *Event { + +} \ No newline at end of file diff --git a/entities/room/roomController.go b/entities/room/roomController.go index 2439df8..75b6679 100644 --- a/entities/room/roomController.go +++ b/entities/room/roomController.go @@ -1,19 +1,5 @@ package room -import "database/sql" - -func createRoom(db *sql.DB) { - -} - -func readRoom(db *sql.DB) { - -} - -func updateRoom(db *sql.DB) { - -} - -func deleteRoom(db *sql.DB) { - -} +func New() room *Room { + +} \ No newline at end of file diff --git a/entities/transaction/transactionController.go b/entities/transaction/transactionController.go index 6dd2dc6..923edfb 100644 --- a/entities/transaction/transactionController.go +++ b/entities/transaction/transactionController.go @@ -1,19 +1,5 @@ package transaction -import "database/sql" - -func createTransaction(db *sql.DB) { - -} - -func readTransaction(db *sql.DB) { - -} - -func updateTransaction(db *sql.DB) { - -} - -func deleteTransaction(db *sql.DB) { - -} +func New() transaction *Transaction { + +} \ No newline at end of file diff --git a/entities/user/userController.go b/entities/user/userController.go index 8f17be8..4bf992c 100644 --- a/entities/user/userController.go +++ b/entities/user/userController.go @@ -1,19 +1,5 @@ package user -import "database/sql" - -func createUser(db *sql.DB) { - -} - -func readUser(db *sql.DB) { - -} - -func updateUser(db *sql.DB) { - -} - -func deleteUser(db *sql.DB) { - -} +func New() user *User { + +} \ No newline at end of file diff --git a/utils/databaseController.go b/utils/database/databaseConnector.go similarity index 71% rename from utils/databaseController.go rename to utils/database/databaseConnector.go index 2a412ff..87a00db 100644 --- a/utils/databaseController.go +++ b/utils/database/databaseConnector.go @@ -1,4 +1,4 @@ -package utils +package database import ( "database/sql" @@ -17,13 +17,22 @@ func InitDB(filepath string) *sql.DB { panic("DB couldn't be initialized") } - // TODO: Change to correct DB-Structure - statement, _ := db.Prepare("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT)") - statement.Exec() + handleError(initDeviceTable(db)) + handleError(initEventTable(db)) + handleError(initRoomTable(db)) + handleError(initTransactionTable(db)) + handleError(initUserTable(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 (id, content) diff --git a/utils/database/deviceDatabaseConnector.go b/utils/database/deviceDatabaseConnector.go new file mode 100644 index 0000000..56efd34 --- /dev/null +++ b/utils/database/deviceDatabaseConnector.go @@ -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 { + +} diff --git a/utils/database/eventDatabaseConnector.go b/utils/database/eventDatabaseConnector.go new file mode 100644 index 0000000..9c94353 --- /dev/null +++ b/utils/database/eventDatabaseConnector.go @@ -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 { + +} diff --git a/utils/database/roomDatabaseConnector.go b/utils/database/roomDatabaseConnector.go new file mode 100644 index 0000000..155210b --- /dev/null +++ b/utils/database/roomDatabaseConnector.go @@ -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 { + +} diff --git a/utils/database/transactionDatabaseConnector.go b/utils/database/transactionDatabaseConnector.go new file mode 100644 index 0000000..6917bcd --- /dev/null +++ b/utils/database/transactionDatabaseConnector.go @@ -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 { + +} diff --git a/utils/database/userDatabaseConnector.go b/utils/database/userDatabaseConnector.go new file mode 100644 index 0000000..f7d96d4 --- /dev/null +++ b/utils/database/userDatabaseConnector.go @@ -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 { + +}