Init Database Methods
This commit is contained in:
parent
a39f23411b
commit
126070829c
11 changed files with 173 additions and 91 deletions
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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)
|
29
utils/database/deviceDatabaseConnector.go
Normal file
29
utils/database/deviceDatabaseConnector.go
Normal 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 {
|
||||
|
||||
}
|
29
utils/database/eventDatabaseConnector.go
Normal file
29
utils/database/eventDatabaseConnector.go
Normal 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 {
|
||||
|
||||
}
|
29
utils/database/roomDatabaseConnector.go
Normal file
29
utils/database/roomDatabaseConnector.go
Normal 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 {
|
||||
|
||||
}
|
29
utils/database/transactionDatabaseConnector.go
Normal file
29
utils/database/transactionDatabaseConnector.go
Normal 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 {
|
||||
|
||||
}
|
29
utils/database/userDatabaseConnector.go
Normal file
29
utils/database/userDatabaseConnector.go
Normal 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 {
|
||||
|
||||
}
|
Loading…
Reference in a new issue