41 lines
977 B
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) {
|
||
|
}
|