Skip to content

Commit

Permalink
feat: ADDED A DATABASE THAT WORKS!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
djpiper28 committed Mar 2, 2024
1 parent 9eb489f commit cfcf942
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
24 changes: 17 additions & 7 deletions kube_cache/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@ package model
import (
"log"

"github.com/google/uuid"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)

type Kube struct {
Name string `json:"name"`
Id string `gorm:"primaryKey" json:"id"`
Image []byte `json:"image"`
Name string `json:"name"`
Id uuid.UUID `gorm:"primaryKey" json:"id"`
// Image []byte `json:"image"`
}

type KubeRecipe struct {
Id string `gorm:"primaryKey" json:"id"`
Output Kube `gorm:"foreignKey:Id;references:Id" json:"output"`
Ingredients []Kube `gorm:"index" json:"ingredients"`
Id uuid.UUID `gorm:"primaryKey" json:"id"`
Output uuid.UUID `json:"outputId" gorm:"index:idx_output_id"`
OutputKube *Kube `json:"outputKube" gorm:"foreignKey:Output;references:Id"`
Ingredients []KubeRecipeLines `json:"ingredients"`
}

type KubeRecipeLines struct {
KubeRecipeId uuid.UUID `json:"kube_recipe_id" gorm:"index:idx_kube_recipe_id"`
KubeId string `json:"kube_id" gorm:"index:idx_kube_id"`
Kube *Kube `json:"kube" gorm:"foreignKey:KubeId;references:Id"`
}

type Database struct {
Expand All @@ -25,7 +33,9 @@ type Database struct {

func New(url string) *Database {
log.Println("Connecting to database...")
db, err := gorm.Open(postgres.Open(url), &gorm.Config{})
db, err := gorm.Open(postgres.Open(url), &gorm.Config{
PrepareStmt: true,
})
if err != nil {
log.Fatal(err)
}
Expand Down
9 changes: 9 additions & 0 deletions kube_cache/server/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package server

import (
"github.com/CosmicKube/kube_cache/model"
)

type Server struct {
Database *model.Database
}

0 comments on commit cfcf942

Please sign in to comment.