This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/db/db.go

41 lines
977 B
Go

package db
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func OpenDB(data) *gorm.DB {
database, _ := gorm.Open(sqlite.Open("./db/imagini.db"), &gorm.Config{
PrepareStmt: true,
})
// Initialize Database
database.AutoMigrate(&ServerSetting{})
database.AutoMigrate(&User{})
database.AutoMigrate(&MediaItem{})
database.AutoMigrate(&Tag{})
database.AutoMigrate(&Album{})
return database
}
func ItemsFromAlbum(userID int, albumID int) []MediaItem {
database, _ := gorm.Open(sqlite.Open("./db/imagini.db"), &gorm.Config{})
database.Raw(`
SELECT
MediaItems.*
FROM
MediaAlbums
INNER JOIN MediaItems ON MediaAlbums.mediaID = MediaItems.mediaID
WHERE MediaAlbums.albumID = ? AND MediaItems.userID = ?`, albumID, userID)
return nil
}
func ItemsFromTags(userID int, tagID int) []MediaItem {
return nil
}
func IndexMediaItems(newItems []MediaItem) {
}