to: add sqlite
This commit is contained in:
parent
50c3e72bf1
commit
5ea6779d75
|
@ -1,9 +1,13 @@
|
|||
package bill
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Bill represents 'bills' object.
|
||||
type Bill struct {
|
||||
gorm.Model
|
||||
ID int `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Date string `json:"date"`
|
||||
|
|
|
@ -2,63 +2,55 @@ package bill
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
QUERY_GET_BILLS = "SELECT * FROM Bills"
|
||||
QUERY_GET_BILLS_BY_DAY = ""
|
||||
QUERY_GET_BILLS_BY_MONTH = ""
|
||||
QUERY_GET_BILLS_BY_YEAR = ""
|
||||
QUERY_GET_BILL_BY_ID = ""
|
||||
)
|
||||
|
||||
type mariaDBRepository struct {
|
||||
mariadb *sql.DB
|
||||
type databaseRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMariaDBRepository(mariadb *sql.DB) BillRepository {
|
||||
return &mariaDBRepository{
|
||||
mariadb: mariadb,
|
||||
func NewDatabaseRepository(db *gorm.DB) BillRepository {
|
||||
return &databaseRepository{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) GetBills(ctx context.Context) (*[]Bill, error) {
|
||||
func (db *databaseRepository) GetBills(ctx context.Context) (*[]Bill, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) GetBillByDay(ctx context.Context, year int, month int, day int) (*[]Bill, error) {
|
||||
func (db *databaseRepository) GetBillByDay(ctx context.Context, year int, month int, day int) (*[]Bill, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error) {
|
||||
func (db *databaseRepository) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) GetBillByYear(ctx context.Context, year int) (*[]Bill, error) {
|
||||
func (db *databaseRepository) GetBillByYear(ctx context.Context, year int) (*[]Bill, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) GetBillByID(ctx context.Context, id int) (*Bill, error) {
|
||||
func (db *databaseRepository) GetBillByID(ctx context.Context, id int) (*Bill, error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) CreateBill(ctx context.Context, bill *Bill) error {
|
||||
func (db *databaseRepository) CreateBill(ctx context.Context, bill *Bill) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) UpdateBill(ctx context.Context, bill *Bill) error {
|
||||
func (db *databaseRepository) UpdateBill(ctx context.Context, bill *Bill) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (m *mariaDBRepository) DeleteBill(ctx context.Context, id int) error {
|
||||
func (db *databaseRepository) DeleteBill(ctx context.Context, id int) error {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ import (
|
|||
// Run our Fiber webserver.
|
||||
func Run() {
|
||||
// Try to connect to our database as the initial part.
|
||||
mariadb, err := ConnectToMariaDB()
|
||||
ConnectToSqlite()
|
||||
//mariadb, err := ConnectToMariaDB()
|
||||
sqlite, err := ConnectToSqlite()
|
||||
if err != nil {
|
||||
log.Fatal("Database connection error: $s", err)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func Run() {
|
|||
// Create repositories.
|
||||
//cityRepository := city.NewCityRepository(mariadb)
|
||||
//userRepository := user.NewUserRepository(mariadb)
|
||||
billRepository := bill.NewMariaDBRepository(mariadb)
|
||||
billRepository := bill.NewDatabaseRepository(sqlite)
|
||||
|
||||
// Create all of our services.
|
||||
//cityService := city.NewCityService(cityRepository)
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
)
|
||||
|
||||
func ConnectToSqlite() (*gorm.DB, error) {
|
||||
dsn := "test.db"
|
||||
dsn := "bill.db"
|
||||
//dsn := "file::memory:?cache=shared"
|
||||
db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("failed to connect database")
|
||||
panic("failed to connect database.\n")
|
||||
}
|
||||
|
||||
return db, nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user