2023-07-05 01:14:44 +02:00
|
|
|
const Path = require('path')
|
2023-12-21 21:29:36 +01:00
|
|
|
const { Sequelize, Op } = require('sequelize')
|
2023-07-05 01:14:44 +02:00
|
|
|
|
|
|
|
const packageJson = require('../package.json')
|
|
|
|
const fs = require('./libs/fsExtra')
|
|
|
|
const Logger = require('./Logger')
|
|
|
|
|
|
|
|
const dbMigration = require('./utils/migrations/dbMigration')
|
2023-07-22 22:32:20 +02:00
|
|
|
const Auth = require('./Auth')
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2024-09-04 11:48:10 +02:00
|
|
|
const MigrationManager = require('./managers/MigrationManager')
|
|
|
|
|
2023-07-05 01:14:44 +02:00
|
|
|
class Database {
|
|
|
|
constructor() {
|
|
|
|
this.sequelize = null
|
|
|
|
this.dbPath = null
|
2023-07-08 21:40:49 +02:00
|
|
|
this.isNew = false // New absdatabase.sqlite created
|
2023-07-22 22:32:20 +02:00
|
|
|
this.hasRootUser = false // Used to show initialization page in web ui
|
2023-07-05 01:14:44 +02:00
|
|
|
|
|
|
|
this.settings = []
|
|
|
|
|
2023-08-13 22:10:26 +02:00
|
|
|
// Cached library filter data
|
|
|
|
this.libraryFilterData = {}
|
|
|
|
|
2023-08-29 00:50:21 +02:00
|
|
|
/** @type {import('./objects/settings/ServerSettings')} */
|
2023-07-05 01:14:44 +02:00
|
|
|
this.serverSettings = null
|
2023-08-29 00:50:21 +02:00
|
|
|
/** @type {import('./objects/settings/NotificationSettings')} */
|
2023-07-05 01:14:44 +02:00
|
|
|
this.notificationSettings = null
|
2023-08-29 00:50:21 +02:00
|
|
|
/** @type {import('./objects/settings/EmailSettings')} */
|
2023-07-05 01:14:44 +02:00
|
|
|
this.emailSettings = null
|
|
|
|
}
|
|
|
|
|
|
|
|
get models() {
|
|
|
|
return this.sequelize?.models || {}
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:34:03 +02:00
|
|
|
/** @type {typeof import('./models/User')} */
|
|
|
|
get userModel() {
|
|
|
|
return this.models.user
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/Library')} */
|
|
|
|
get libraryModel() {
|
|
|
|
return this.models.library
|
|
|
|
}
|
|
|
|
|
2023-09-04 00:51:58 +02:00
|
|
|
/** @type {typeof import('./models/LibraryFolder')} */
|
|
|
|
get libraryFolderModel() {
|
|
|
|
return this.models.libraryFolder
|
|
|
|
}
|
|
|
|
|
2023-08-18 21:40:36 +02:00
|
|
|
/** @type {typeof import('./models/Author')} */
|
|
|
|
get authorModel() {
|
|
|
|
return this.models.author
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/Series')} */
|
|
|
|
get seriesModel() {
|
|
|
|
return this.models.series
|
|
|
|
}
|
|
|
|
|
2023-08-19 20:59:22 +02:00
|
|
|
/** @type {typeof import('./models/Book')} */
|
|
|
|
get bookModel() {
|
|
|
|
return this.models.book
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:34:03 +02:00
|
|
|
/** @type {typeof import('./models/BookSeries')} */
|
|
|
|
get bookSeriesModel() {
|
|
|
|
return this.models.bookSeries
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/BookAuthor')} */
|
|
|
|
get bookAuthorModel() {
|
|
|
|
return this.models.bookAuthor
|
|
|
|
}
|
|
|
|
|
2023-08-19 20:59:22 +02:00
|
|
|
/** @type {typeof import('./models/Podcast')} */
|
|
|
|
get podcastModel() {
|
|
|
|
return this.models.podcast
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:34:03 +02:00
|
|
|
/** @type {typeof import('./models/PodcastEpisode')} */
|
|
|
|
get podcastEpisodeModel() {
|
|
|
|
return this.models.podcastEpisode
|
|
|
|
}
|
|
|
|
|
2023-08-19 20:59:22 +02:00
|
|
|
/** @type {typeof import('./models/LibraryItem')} */
|
|
|
|
get libraryItemModel() {
|
|
|
|
return this.models.libraryItem
|
|
|
|
}
|
|
|
|
|
2023-08-19 21:49:06 +02:00
|
|
|
/** @type {typeof import('./models/PodcastEpisode')} */
|
|
|
|
get podcastEpisodeModel() {
|
|
|
|
return this.models.podcastEpisode
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/MediaProgress')} */
|
|
|
|
get mediaProgressModel() {
|
|
|
|
return this.models.mediaProgress
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:34:03 +02:00
|
|
|
/** @type {typeof import('./models/Collection')} */
|
|
|
|
get collectionModel() {
|
|
|
|
return this.models.collection
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/CollectionBook')} */
|
|
|
|
get collectionBookModel() {
|
|
|
|
return this.models.collectionBook
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/Playlist')} */
|
|
|
|
get playlistModel() {
|
|
|
|
return this.models.playlist
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/PlaylistMediaItem')} */
|
|
|
|
get playlistMediaItemModel() {
|
|
|
|
return this.models.playlistMediaItem
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @type {typeof import('./models/Feed')} */
|
|
|
|
get feedModel() {
|
|
|
|
return this.models.feed
|
|
|
|
}
|
|
|
|
|
2023-12-20 00:19:33 +01:00
|
|
|
/** @type {typeof import('./models/FeedEpisode')} */
|
2023-08-20 20:34:03 +02:00
|
|
|
get feedEpisodeModel() {
|
|
|
|
return this.models.feedEpisode
|
|
|
|
}
|
|
|
|
|
2023-12-20 00:19:33 +01:00
|
|
|
/** @type {typeof import('./models/PlaybackSession')} */
|
|
|
|
get playbackSessionModel() {
|
|
|
|
return this.models.playbackSession
|
|
|
|
}
|
|
|
|
|
2024-01-03 01:36:56 +01:00
|
|
|
/** @type {typeof import('./models/CustomMetadataProvider')} */
|
|
|
|
get customMetadataProviderModel() {
|
|
|
|
return this.models.customMetadataProvider
|
|
|
|
}
|
|
|
|
|
2024-06-27 00:03:12 +02:00
|
|
|
/** @type {typeof import('./models/MediaItemShare')} */
|
|
|
|
get mediaItemShareModel() {
|
|
|
|
return this.models.mediaItemShare
|
|
|
|
}
|
|
|
|
|
2024-09-12 23:36:39 +02:00
|
|
|
/** @type {typeof import('./models/Device')} */
|
|
|
|
get deviceModel() {
|
|
|
|
return this.models.device
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Check if db file exists
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2023-07-05 01:14:44 +02:00
|
|
|
async checkHasDb() {
|
2024-06-22 23:42:13 +02:00
|
|
|
if (!(await fs.pathExists(this.dbPath))) {
|
2023-07-08 21:40:49 +02:00
|
|
|
Logger.info(`[Database] absdatabase.sqlite not found at ${this.dbPath}`)
|
2023-07-05 01:14:44 +02:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Connect to db, build models and run migrations
|
|
|
|
* @param {boolean} [force=false] Used for testing, drops & re-creates all tables
|
|
|
|
*/
|
2023-07-05 01:14:44 +02:00
|
|
|
async init(force = false) {
|
2023-07-08 21:40:49 +02:00
|
|
|
this.dbPath = Path.join(global.ConfigPath, 'absdatabase.sqlite')
|
2023-07-05 01:14:44 +02:00
|
|
|
|
|
|
|
// First check if this is a new database
|
|
|
|
this.isNew = !(await this.checkHasDb()) || force
|
|
|
|
|
2024-06-22 23:42:13 +02:00
|
|
|
if (!(await this.connect())) {
|
2023-07-05 01:14:44 +02:00
|
|
|
throw new Error('Database connection failed')
|
|
|
|
}
|
|
|
|
|
2024-09-07 21:24:19 +02:00
|
|
|
try {
|
2024-09-14 07:01:32 +02:00
|
|
|
const migrationManager = new MigrationManager(this.sequelize, this.isNew, global.ConfigPath)
|
2024-09-07 21:24:19 +02:00
|
|
|
await migrationManager.init(packageJson.version)
|
2024-09-14 07:01:32 +02:00
|
|
|
await migrationManager.runMigrations()
|
2024-09-07 21:24:19 +02:00
|
|
|
} catch (error) {
|
|
|
|
Logger.error(`[Database] Failed to run migrations`, error)
|
|
|
|
throw new Error('Database migration failed')
|
2024-09-04 11:48:10 +02:00
|
|
|
}
|
|
|
|
|
2023-07-05 01:14:44 +02:00
|
|
|
await this.buildModels(force)
|
2023-07-14 21:50:37 +02:00
|
|
|
Logger.info(`[Database] Db initialized with models:`, Object.keys(this.sequelize.models).join(', '))
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2023-07-08 21:40:49 +02:00
|
|
|
await this.loadData()
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Connect to db
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2023-07-05 01:14:44 +02:00
|
|
|
async connect() {
|
|
|
|
Logger.info(`[Database] Initializing db at "${this.dbPath}"`)
|
2023-09-15 07:52:43 +02:00
|
|
|
|
2023-09-22 23:14:12 +02:00
|
|
|
let logging = false
|
|
|
|
let benchmark = false
|
2024-06-22 23:42:13 +02:00
|
|
|
if (process.env.QUERY_LOGGING === 'log') {
|
2023-09-15 07:52:43 +02:00
|
|
|
// Setting QUERY_LOGGING=log will log all Sequelize queries before they run
|
2023-09-15 08:04:47 +02:00
|
|
|
Logger.info(`[Database] Query logging enabled`)
|
2024-01-04 00:19:28 +01:00
|
|
|
logging = (query) => Logger.debug(`Running the following query:\n ${query}`)
|
2024-06-22 23:42:13 +02:00
|
|
|
} else if (process.env.QUERY_LOGGING === 'benchmark') {
|
2023-09-15 07:52:43 +02:00
|
|
|
// Setting QUERY_LOGGING=benchmark will log all Sequelize queries and their execution times, after they run
|
|
|
|
Logger.info(`[Database] Query benchmarking enabled"`)
|
2024-01-04 00:19:28 +01:00
|
|
|
logging = (query, time) => Logger.debug(`Ran the following query in ${time}ms:\n ${query}`)
|
2023-09-22 23:14:00 +02:00
|
|
|
benchmark = true
|
2023-09-15 07:52:43 +02:00
|
|
|
}
|
|
|
|
|
2023-07-05 01:14:44 +02:00
|
|
|
this.sequelize = new Sequelize({
|
|
|
|
dialect: 'sqlite',
|
|
|
|
storage: this.dbPath,
|
2023-09-15 07:52:43 +02:00
|
|
|
logging: logging,
|
|
|
|
benchmark: benchmark,
|
2023-07-22 18:30:29 +02:00
|
|
|
transactionType: 'IMMEDIATE'
|
2023-07-05 01:14:44 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// Helper function
|
2024-06-22 23:42:13 +02:00
|
|
|
this.sequelize.uppercaseFirst = (str) => (str ? `${str[0].toUpperCase()}${str.substr(1)}` : '')
|
2023-07-05 01:14:44 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
await this.sequelize.authenticate()
|
|
|
|
Logger.info(`[Database] Db connection was successful`)
|
|
|
|
return true
|
|
|
|
} catch (error) {
|
|
|
|
Logger.error(`[Database] Failed to connect to db`, error)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-28 23:55:45 +02:00
|
|
|
/**
|
2024-08-09 23:41:52 +02:00
|
|
|
* TODO: Temporarily disabled
|
2024-07-28 23:55:45 +02:00
|
|
|
* @param {string[]} extensions paths to extension binaries
|
|
|
|
*/
|
2024-07-27 20:56:07 +02:00
|
|
|
async loadExtensions(extensions) {
|
|
|
|
// This is a hack to get the db connection for loading extensions.
|
|
|
|
// The proper way would be to use the 'afterConnect' hook, but that hook is never called for sqlite due to a bug in sequelize.
|
|
|
|
// See https://github.com/sequelize/sequelize/issues/12487
|
|
|
|
// This is not a public API and may break in the future.
|
|
|
|
const db = await this.sequelize.dialect.connectionManager.getConnection()
|
|
|
|
if (typeof db?.loadExtension !== 'function') throw new Error('Failed to get db connection for loading extensions')
|
|
|
|
|
|
|
|
for (const ext of extensions) {
|
|
|
|
Logger.info(`[Database] Loading extension ${ext}`)
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
db.loadExtension(ext, (err) => {
|
|
|
|
if (err) {
|
|
|
|
Logger.error(`[Database] Failed to load extension ${ext}`, err)
|
|
|
|
reject(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
Logger.info(`[Database] Successfully loaded extension ${ext}`)
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Disconnect from db
|
|
|
|
*/
|
2023-07-08 21:40:49 +02:00
|
|
|
async disconnect() {
|
|
|
|
Logger.info(`[Database] Disconnecting sqlite db`)
|
|
|
|
await this.sequelize.close()
|
|
|
|
}
|
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Reconnect to db and init
|
|
|
|
*/
|
2023-07-08 21:40:49 +02:00
|
|
|
async reconnect() {
|
|
|
|
Logger.info(`[Database] Reconnecting sqlite db`)
|
|
|
|
await this.init()
|
|
|
|
}
|
|
|
|
|
2023-07-05 01:14:44 +02:00
|
|
|
buildModels(force = false) {
|
2023-08-16 23:38:48 +02:00
|
|
|
require('./models/User').init(this.sequelize)
|
2023-08-16 01:03:43 +02:00
|
|
|
require('./models/Library').init(this.sequelize)
|
|
|
|
require('./models/LibraryFolder').init(this.sequelize)
|
|
|
|
require('./models/Book').init(this.sequelize)
|
2023-08-16 23:38:48 +02:00
|
|
|
require('./models/Podcast').init(this.sequelize)
|
|
|
|
require('./models/PodcastEpisode').init(this.sequelize)
|
|
|
|
require('./models/LibraryItem').init(this.sequelize)
|
|
|
|
require('./models/MediaProgress').init(this.sequelize)
|
|
|
|
require('./models/Series').init(this.sequelize)
|
2023-08-16 01:03:43 +02:00
|
|
|
require('./models/BookSeries').init(this.sequelize)
|
2023-08-15 01:22:38 +02:00
|
|
|
require('./models/Author').init(this.sequelize)
|
2023-08-16 01:03:43 +02:00
|
|
|
require('./models/BookAuthor').init(this.sequelize)
|
|
|
|
require('./models/Collection').init(this.sequelize)
|
|
|
|
require('./models/CollectionBook').init(this.sequelize)
|
2023-08-16 23:38:48 +02:00
|
|
|
require('./models/Playlist').init(this.sequelize)
|
|
|
|
require('./models/PlaylistMediaItem').init(this.sequelize)
|
2023-08-16 01:03:43 +02:00
|
|
|
require('./models/Device').init(this.sequelize)
|
2023-08-16 23:38:48 +02:00
|
|
|
require('./models/PlaybackSession').init(this.sequelize)
|
2023-08-16 01:03:43 +02:00
|
|
|
require('./models/Feed').init(this.sequelize)
|
|
|
|
require('./models/FeedEpisode').init(this.sequelize)
|
2023-08-16 23:38:48 +02:00
|
|
|
require('./models/Setting').init(this.sequelize)
|
2024-01-03 01:36:56 +01:00
|
|
|
require('./models/CustomMetadataProvider').init(this.sequelize)
|
2024-06-22 23:42:13 +02:00
|
|
|
require('./models/MediaItemShare').init(this.sequelize)
|
2023-07-05 01:14:44 +02:00
|
|
|
|
2023-07-06 01:18:37 +02:00
|
|
|
return this.sequelize.sync({ force, alter: false })
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2023-07-21 23:59:00 +02:00
|
|
|
/**
|
|
|
|
* Compare two server versions
|
2024-06-22 23:42:13 +02:00
|
|
|
* @param {string} v1
|
|
|
|
* @param {string} v2
|
2023-07-21 23:59:00 +02:00
|
|
|
* @returns {-1|0|1} 1 if v1 > v2
|
|
|
|
*/
|
|
|
|
compareVersions(v1, v2) {
|
|
|
|
if (!v1 || !v2) return 0
|
2024-06-22 23:42:13 +02:00
|
|
|
return v1.localeCompare(v2, undefined, { numeric: true, sensitivity: 'case', caseFirst: 'upper' })
|
2023-07-21 23:59:00 +02:00
|
|
|
}
|
|
|
|
|
2023-07-19 22:36:18 +02:00
|
|
|
/**
|
|
|
|
* Checks if migration to sqlite db is necessary & runs migration.
|
2024-06-22 23:42:13 +02:00
|
|
|
*
|
2023-07-19 22:36:18 +02:00
|
|
|
* Check if version was upgraded and run any version specific migrations.
|
2024-06-22 23:42:13 +02:00
|
|
|
*
|
2023-07-19 22:36:18 +02:00
|
|
|
* Loads most of the data from the database. This is a temporary solution.
|
|
|
|
*/
|
2023-07-08 21:40:49 +02:00
|
|
|
async loadData() {
|
2024-06-22 23:42:13 +02:00
|
|
|
if (this.isNew && (await dbMigration.checkShouldMigrate())) {
|
2023-07-05 01:14:44 +02:00
|
|
|
Logger.info(`[Database] New database was created and old database was detected - migrating old to new`)
|
|
|
|
await dbMigration.migrate(this.models)
|
|
|
|
}
|
|
|
|
|
2023-07-16 22:05:51 +02:00
|
|
|
const settingsData = await this.models.setting.getOldSettings()
|
|
|
|
this.settings = settingsData.settings
|
|
|
|
this.emailSettings = settingsData.emailSettings
|
|
|
|
this.serverSettings = settingsData.serverSettings
|
|
|
|
this.notificationSettings = settingsData.notificationSettings
|
|
|
|
global.ServerSettings = this.serverSettings.toJSON()
|
|
|
|
|
|
|
|
// Version specific migrations
|
2023-10-22 22:53:05 +02:00
|
|
|
if (packageJson.version !== this.serverSettings.version) {
|
|
|
|
if (this.serverSettings.version === '2.3.0' && this.compareVersions(packageJson.version, '2.3.0') == 1) {
|
|
|
|
await dbMigration.migrationPatch(this)
|
|
|
|
}
|
|
|
|
if (['2.3.0', '2.3.1', '2.3.2', '2.3.3'].includes(this.serverSettings.version) && this.compareVersions(packageJson.version, '2.3.3') >= 0) {
|
|
|
|
await dbMigration.migrationPatch2(this)
|
|
|
|
}
|
2023-07-29 01:03:31 +02:00
|
|
|
}
|
2023-10-22 22:53:05 +02:00
|
|
|
// Build migrations
|
|
|
|
if (this.serverSettings.buildNumber <= 0) {
|
|
|
|
await require('./utils/migrations/absMetadataMigration').migrate(this)
|
2023-07-16 22:05:51 +02:00
|
|
|
}
|
|
|
|
|
2023-09-09 00:20:39 +02:00
|
|
|
await this.cleanDatabase()
|
|
|
|
|
2023-07-22 22:32:20 +02:00
|
|
|
// Set if root user has been created
|
|
|
|
this.hasRootUser = await this.models.user.getHasRootUser()
|
|
|
|
|
2023-10-22 22:53:05 +02:00
|
|
|
// Update server settings with version/build
|
|
|
|
let updateServerSettings = false
|
2023-07-05 01:14:44 +02:00
|
|
|
if (packageJson.version !== this.serverSettings.version) {
|
|
|
|
Logger.info(`[Database] Server upgrade detected from ${this.serverSettings.version} to ${packageJson.version}`)
|
|
|
|
this.serverSettings.version = packageJson.version
|
2023-10-22 22:53:05 +02:00
|
|
|
this.serverSettings.buildNumber = packageJson.buildNumber
|
|
|
|
updateServerSettings = true
|
|
|
|
} else if (packageJson.buildNumber !== this.serverSettings.buildNumber) {
|
|
|
|
Logger.info(`[Database] Server v${packageJson.version} build upgraded from ${this.serverSettings.buildNumber} to ${packageJson.buildNumber}`)
|
|
|
|
this.serverSettings.buildNumber = packageJson.buildNumber
|
|
|
|
updateServerSettings = true
|
|
|
|
}
|
|
|
|
if (updateServerSettings) {
|
2023-07-05 01:14:44 +02:00
|
|
|
await this.updateServerSettings()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 22:32:20 +02:00
|
|
|
/**
|
|
|
|
* Create root user
|
2024-06-22 23:42:13 +02:00
|
|
|
* @param {string} username
|
|
|
|
* @param {string} pash
|
|
|
|
* @param {Auth} auth
|
2024-08-18 00:18:40 +02:00
|
|
|
* @returns {Promise<boolean>} true if created
|
2023-07-22 22:32:20 +02:00
|
|
|
*/
|
|
|
|
async createRootUser(username, pash, auth) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2024-08-10 22:46:04 +02:00
|
|
|
await this.userModel.createRootUser(username, pash, auth)
|
2023-07-22 22:32:20 +02:00
|
|
|
this.hasRootUser = true
|
|
|
|
return true
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateServerSettings() {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
global.ServerSettings = this.serverSettings.toJSON()
|
|
|
|
return this.updateSetting(this.serverSettings)
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSetting(settings) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.setting.updateSettingObj(settings.toJSON())
|
|
|
|
}
|
|
|
|
|
|
|
|
updateBulkBooks(oldBooks) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2024-06-22 23:42:13 +02:00
|
|
|
return Promise.all(oldBooks.map((oldBook) => this.models.book.saveFromOld(oldBook)))
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2023-09-03 22:14:58 +02:00
|
|
|
removeLibrary(libraryId) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-09-03 22:14:58 +02:00
|
|
|
return this.models.library.removeById(libraryId)
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createBulkCollectionBooks(collectionBooks) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.collectionBook.bulkCreate(collectionBooks)
|
|
|
|
}
|
|
|
|
|
|
|
|
createPlaylistMediaItem(playlistMediaItem) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playlistMediaItem.create(playlistMediaItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
createBulkPlaylistMediaItems(playlistMediaItems) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playlistMediaItem.bulkCreate(playlistMediaItems)
|
|
|
|
}
|
|
|
|
|
|
|
|
async createLibraryItem(oldLibraryItem) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-22 14:50:47 +02:00
|
|
|
await oldLibraryItem.saveMetadata()
|
2023-07-05 01:14:44 +02:00
|
|
|
await this.models.libraryItem.fullCreateFromOld(oldLibraryItem)
|
|
|
|
}
|
|
|
|
|
2024-02-18 21:58:46 +01:00
|
|
|
/**
|
|
|
|
* Save metadata file and update library item
|
2024-06-22 23:42:13 +02:00
|
|
|
*
|
|
|
|
* @param {import('./objects/LibraryItem')} oldLibraryItem
|
2024-02-18 21:58:46 +01:00
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
2023-07-22 14:50:47 +02:00
|
|
|
async updateLibraryItem(oldLibraryItem) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-22 14:50:47 +02:00
|
|
|
await oldLibraryItem.saveMetadata()
|
2024-02-18 21:58:46 +01:00
|
|
|
const updated = await this.models.libraryItem.fullUpdateFromOld(oldLibraryItem)
|
|
|
|
// Clear library filter data cache
|
2024-03-09 11:07:08 +01:00
|
|
|
if (updated) {
|
2024-02-18 21:58:46 +01:00
|
|
|
delete this.libraryFilterData[oldLibraryItem.libraryId]
|
|
|
|
}
|
|
|
|
return updated
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2023-07-06 01:18:37 +02:00
|
|
|
async createFeed(oldFeed) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-06 01:18:37 +02:00
|
|
|
await this.models.feed.fullCreateFromOld(oldFeed)
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
updateFeed(oldFeed) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-06 01:18:37 +02:00
|
|
|
return this.models.feed.fullUpdateFromOld(oldFeed)
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async removeFeed(feedId) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
await this.models.feed.removeById(feedId)
|
|
|
|
}
|
|
|
|
|
|
|
|
async createBulkBookAuthors(bookAuthors) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
await this.models.bookAuthor.bulkCreate(bookAuthors)
|
|
|
|
}
|
|
|
|
|
|
|
|
async removeBulkBookAuthors(authorId = null, bookId = null) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
if (!authorId && !bookId) return
|
|
|
|
await this.models.bookAuthor.removeByIds(authorId, bookId)
|
|
|
|
}
|
|
|
|
|
|
|
|
getPlaybackSessions(where = null) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playbackSession.getOldPlaybackSessions(where)
|
|
|
|
}
|
|
|
|
|
|
|
|
getPlaybackSession(sessionId) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playbackSession.getById(sessionId)
|
|
|
|
}
|
|
|
|
|
|
|
|
createPlaybackSession(oldSession) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playbackSession.createFromOld(oldSession)
|
|
|
|
}
|
|
|
|
|
|
|
|
updatePlaybackSession(oldSession) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playbackSession.updateFromOld(oldSession)
|
|
|
|
}
|
|
|
|
|
|
|
|
removePlaybackSession(sessionId) {
|
2023-07-08 21:40:49 +02:00
|
|
|
if (!this.sequelize) return false
|
2023-07-05 01:14:44 +02:00
|
|
|
return this.models.playbackSession.removeById(sessionId)
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:01:17 +02:00
|
|
|
replaceTagInFilterData(oldTag, newTag) {
|
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
const indexOf = this.libraryFilterData[libraryId].tags.findIndex((n) => n === oldTag)
|
2023-09-02 01:01:17 +02:00
|
|
|
if (indexOf >= 0) {
|
|
|
|
this.libraryFilterData[libraryId].tags.splice(indexOf, 1, newTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-13 22:10:26 +02:00
|
|
|
removeTagFromFilterData(tag) {
|
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
this.libraryFilterData[libraryId].tags = this.libraryFilterData[libraryId].tags.filter((t) => t !== tag)
|
2023-08-13 22:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:01:17 +02:00
|
|
|
addTagsToFilterData(libraryId, tags) {
|
|
|
|
if (!this.libraryFilterData[libraryId] || !tags?.length) return
|
|
|
|
tags.forEach((t) => {
|
|
|
|
if (!this.libraryFilterData[libraryId].tags.includes(t)) {
|
|
|
|
this.libraryFilterData[libraryId].tags.push(t)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceGenreInFilterData(oldGenre, newGenre) {
|
2023-08-13 22:10:26 +02:00
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
const indexOf = this.libraryFilterData[libraryId].genres.findIndex((n) => n === oldGenre)
|
2023-09-02 01:01:17 +02:00
|
|
|
if (indexOf >= 0) {
|
|
|
|
this.libraryFilterData[libraryId].genres.splice(indexOf, 1, newGenre)
|
2023-08-13 22:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeGenreFromFilterData(genre) {
|
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
this.libraryFilterData[libraryId].genres = this.libraryFilterData[libraryId].genres.filter((g) => g !== genre)
|
2023-08-13 22:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:01:17 +02:00
|
|
|
addGenresToFilterData(libraryId, genres) {
|
|
|
|
if (!this.libraryFilterData[libraryId] || !genres?.length) return
|
|
|
|
genres.forEach((g) => {
|
|
|
|
if (!this.libraryFilterData[libraryId].genres.includes(g)) {
|
|
|
|
this.libraryFilterData[libraryId].genres.push(g)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
replaceNarratorInFilterData(oldNarrator, newNarrator) {
|
2023-08-13 22:10:26 +02:00
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
const indexOf = this.libraryFilterData[libraryId].narrators.findIndex((n) => n === oldNarrator)
|
2023-09-02 01:01:17 +02:00
|
|
|
if (indexOf >= 0) {
|
|
|
|
this.libraryFilterData[libraryId].narrators.splice(indexOf, 1, newNarrator)
|
2023-08-13 22:10:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-14 00:45:53 +02:00
|
|
|
|
|
|
|
removeNarratorFromFilterData(narrator) {
|
|
|
|
for (const libraryId in this.libraryFilterData) {
|
2024-06-22 23:42:13 +02:00
|
|
|
this.libraryFilterData[libraryId].narrators = this.libraryFilterData[libraryId].narrators.filter((n) => n !== narrator)
|
2023-08-14 00:45:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:01:17 +02:00
|
|
|
addNarratorsToFilterData(libraryId, narrators) {
|
|
|
|
if (!this.libraryFilterData[libraryId] || !narrators?.length) return
|
|
|
|
narrators.forEach((n) => {
|
|
|
|
if (!this.libraryFilterData[libraryId].narrators.includes(n)) {
|
|
|
|
this.libraryFilterData[libraryId].narrators.push(n)
|
2023-08-14 00:45:53 +02:00
|
|
|
}
|
2023-09-02 01:01:17 +02:00
|
|
|
})
|
2023-08-14 00:45:53 +02:00
|
|
|
}
|
2023-08-18 21:40:36 +02:00
|
|
|
|
|
|
|
removeSeriesFromFilterData(libraryId, seriesId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) return
|
2024-06-22 23:42:13 +02:00
|
|
|
this.libraryFilterData[libraryId].series = this.libraryFilterData[libraryId].series.filter((se) => se.id !== seriesId)
|
2023-08-18 21:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addSeriesToFilterData(libraryId, seriesName, seriesId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) return
|
|
|
|
// Check if series is already added
|
2024-06-22 23:42:13 +02:00
|
|
|
if (this.libraryFilterData[libraryId].series.some((se) => se.id === seriesId)) return
|
2023-08-18 21:40:36 +02:00
|
|
|
this.libraryFilterData[libraryId].series.push({
|
|
|
|
id: seriesId,
|
|
|
|
name: seriesName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
removeAuthorFromFilterData(libraryId, authorId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) return
|
2024-06-22 23:42:13 +02:00
|
|
|
this.libraryFilterData[libraryId].authors = this.libraryFilterData[libraryId].authors.filter((au) => au.id !== authorId)
|
2023-08-18 21:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addAuthorToFilterData(libraryId, authorName, authorId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) return
|
|
|
|
// Check if author is already added
|
2024-06-22 23:42:13 +02:00
|
|
|
if (this.libraryFilterData[libraryId].authors.some((au) => au.id === authorId)) return
|
2023-08-18 21:40:36 +02:00
|
|
|
this.libraryFilterData[libraryId].authors.push({
|
|
|
|
id: authorId,
|
|
|
|
name: authorName
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-02 01:01:17 +02:00
|
|
|
addPublisherToFilterData(libraryId, publisher) {
|
|
|
|
if (!this.libraryFilterData[libraryId] || !publisher || this.libraryFilterData[libraryId].publishers.includes(publisher)) return
|
|
|
|
this.libraryFilterData[libraryId].publishers.push(publisher)
|
|
|
|
}
|
|
|
|
|
|
|
|
addLanguageToFilterData(libraryId, language) {
|
|
|
|
if (!this.libraryFilterData[libraryId] || !language || this.libraryFilterData[libraryId].languages.includes(language)) return
|
|
|
|
this.libraryFilterData[libraryId].languages.push(language)
|
|
|
|
}
|
|
|
|
|
2023-08-18 21:40:36 +02:00
|
|
|
/**
|
|
|
|
* Used when updating items to make sure author id exists
|
|
|
|
* If library filter data is set then use that for check
|
|
|
|
* otherwise lookup in db
|
2024-06-22 23:42:13 +02:00
|
|
|
* @param {string} libraryId
|
|
|
|
* @param {string} authorId
|
2023-08-18 21:40:36 +02:00
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
async checkAuthorExists(libraryId, authorId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) {
|
|
|
|
return this.authorModel.checkExistsById(authorId)
|
|
|
|
}
|
2024-06-22 23:42:13 +02:00
|
|
|
return this.libraryFilterData[libraryId].authors.some((au) => au.id === authorId)
|
2023-08-18 21:40:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used when updating items to make sure series id exists
|
|
|
|
* If library filter data is set then use that for check
|
|
|
|
* otherwise lookup in db
|
2024-06-22 23:42:13 +02:00
|
|
|
* @param {string} libraryId
|
|
|
|
* @param {string} seriesId
|
2023-08-18 21:40:36 +02:00
|
|
|
* @returns {Promise<boolean>}
|
|
|
|
*/
|
|
|
|
async checkSeriesExists(libraryId, seriesId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) {
|
|
|
|
return this.seriesModel.checkExistsById(seriesId)
|
|
|
|
}
|
2024-06-22 23:42:13 +02:00
|
|
|
return this.libraryFilterData[libraryId].series.some((se) => se.id === seriesId)
|
2023-08-18 21:40:36 +02:00
|
|
|
}
|
2023-08-20 20:16:53 +02:00
|
|
|
|
2024-03-11 23:07:03 +01:00
|
|
|
/**
|
|
|
|
* Get author id for library by name. Uses library filter data if available
|
2024-06-22 23:42:13 +02:00
|
|
|
*
|
|
|
|
* @param {string} libraryId
|
|
|
|
* @param {string} authorName
|
|
|
|
* @returns {Promise<string>} author id or null if not found
|
2024-03-11 23:07:03 +01:00
|
|
|
*/
|
|
|
|
async getAuthorIdByName(libraryId, authorName) {
|
2024-03-09 10:59:50 +01:00
|
|
|
if (!this.libraryFilterData[libraryId]) {
|
2024-08-31 20:27:48 +02:00
|
|
|
return (await this.authorModel.getByNameAndLibrary(authorName, libraryId))?.id || null
|
2024-03-09 10:59:50 +01:00
|
|
|
}
|
2024-06-22 23:42:13 +02:00
|
|
|
return this.libraryFilterData[libraryId].authors.find((au) => au.name === authorName)?.id || null
|
2024-03-09 10:59:50 +01:00
|
|
|
}
|
|
|
|
|
2024-03-11 23:07:03 +01:00
|
|
|
/**
|
|
|
|
* Get series id for library by name. Uses library filter data if available
|
2024-06-22 23:42:13 +02:00
|
|
|
*
|
|
|
|
* @param {string} libraryId
|
|
|
|
* @param {string} seriesName
|
2024-03-11 23:07:03 +01:00
|
|
|
* @returns {Promise<string>} series id or null if not found
|
|
|
|
*/
|
|
|
|
async getSeriesIdByName(libraryId, seriesName) {
|
2024-03-09 10:59:50 +01:00
|
|
|
if (!this.libraryFilterData[libraryId]) {
|
2024-09-01 22:08:56 +02:00
|
|
|
return (await this.seriesModel.getByNameAndLibrary(seriesName, libraryId))?.id || null
|
2024-03-09 10:59:50 +01:00
|
|
|
}
|
2024-06-22 23:42:13 +02:00
|
|
|
return this.libraryFilterData[libraryId].series.find((se) => se.name === seriesName)?.id || null
|
2024-03-11 23:07:03 +01:00
|
|
|
}
|
2024-03-09 10:59:50 +01:00
|
|
|
|
2023-08-20 20:16:53 +02:00
|
|
|
/**
|
|
|
|
* Reset numIssues for library
|
2024-06-22 23:42:13 +02:00
|
|
|
* @param {string} libraryId
|
2023-08-20 20:16:53 +02:00
|
|
|
*/
|
|
|
|
async resetLibraryIssuesFilterData(libraryId) {
|
|
|
|
if (!this.libraryFilterData[libraryId]) return // Do nothing if filter data is not set
|
|
|
|
|
|
|
|
this.libraryFilterData[libraryId].numIssues = await this.libraryItemModel.count({
|
|
|
|
where: {
|
|
|
|
libraryId,
|
|
|
|
[Sequelize.Op.or]: [
|
|
|
|
{
|
|
|
|
isMissing: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
isInvalid: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2023-09-06 00:58:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean invalid records in database
|
|
|
|
* Series should have atleast one Book
|
|
|
|
* Book and Podcast must have an associated LibraryItem
|
2023-12-21 21:29:36 +01:00
|
|
|
* Remove playback sessions that are 3 seconds or less
|
2023-09-06 00:58:13 +02:00
|
|
|
*/
|
|
|
|
async cleanDatabase() {
|
|
|
|
// Remove invalid Podcast records
|
|
|
|
const podcastsWithNoLibraryItem = await this.podcastModel.findAll({
|
2023-09-17 22:53:25 +02:00
|
|
|
include: {
|
|
|
|
model: this.libraryItemModel,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
where: { '$libraryItem.id$': null }
|
2023-09-06 00:58:13 +02:00
|
|
|
})
|
|
|
|
for (const podcast of podcastsWithNoLibraryItem) {
|
|
|
|
Logger.warn(`Found podcast "${podcast.title}" with no libraryItem - removing it`)
|
|
|
|
await podcast.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove invalid Book records
|
|
|
|
const booksWithNoLibraryItem = await this.bookModel.findAll({
|
2023-09-17 22:53:25 +02:00
|
|
|
include: {
|
|
|
|
model: this.libraryItemModel,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
where: { '$libraryItem.id$': null }
|
2023-09-06 00:58:13 +02:00
|
|
|
})
|
|
|
|
for (const book of booksWithNoLibraryItem) {
|
|
|
|
Logger.warn(`Found book "${book.title}" with no libraryItem - removing it`)
|
|
|
|
await book.destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove empty series
|
|
|
|
const emptySeries = await this.seriesModel.findAll({
|
2023-09-17 22:53:25 +02:00
|
|
|
include: {
|
|
|
|
model: this.bookSeriesModel,
|
|
|
|
required: false
|
|
|
|
},
|
|
|
|
where: { '$bookSeries.id$': null }
|
2023-09-06 00:58:13 +02:00
|
|
|
})
|
|
|
|
for (const series of emptySeries) {
|
|
|
|
Logger.warn(`Found series "${series.name}" with no books - removing it`)
|
|
|
|
await series.destroy()
|
|
|
|
}
|
2023-12-21 21:29:36 +01:00
|
|
|
|
|
|
|
// Remove playback sessions that were 3 seconds or less
|
|
|
|
const badSessionsRemoved = await this.playbackSessionModel.destroy({
|
|
|
|
where: {
|
|
|
|
timeListening: {
|
|
|
|
[Op.lte]: 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (badSessionsRemoved > 0) {
|
|
|
|
Logger.warn(`Removed ${badSessionsRemoved} sessions that were 3 seconds or less`)
|
|
|
|
}
|
2023-09-06 00:58:13 +02:00
|
|
|
}
|
2024-07-27 20:56:07 +02:00
|
|
|
|
2024-07-28 23:55:45 +02:00
|
|
|
/**
|
2024-08-09 23:41:52 +02:00
|
|
|
* TODO: Temporarily unused
|
2024-07-28 23:55:45 +02:00
|
|
|
* @param {string} value
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2024-07-27 20:56:07 +02:00
|
|
|
normalize(value) {
|
|
|
|
return `lower(unaccent(${value}))`
|
|
|
|
}
|
|
|
|
|
2024-07-28 23:55:45 +02:00
|
|
|
/**
|
2024-08-09 23:41:52 +02:00
|
|
|
* TODO: Temporarily unused
|
2024-07-28 23:55:45 +02:00
|
|
|
* @param {string} query
|
|
|
|
* @returns {Promise<string>}
|
|
|
|
*/
|
2024-07-27 20:56:07 +02:00
|
|
|
async getNormalizedQuery(query) {
|
|
|
|
const escapedQuery = this.sequelize.escape(query)
|
|
|
|
const normalizedQuery = this.normalize(escapedQuery)
|
|
|
|
const normalizedQueryResult = await this.sequelize.query(`SELECT ${normalizedQuery} as normalized_query`)
|
|
|
|
return normalizedQueryResult[0][0].normalized_query
|
|
|
|
}
|
|
|
|
|
2024-07-28 23:55:45 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} column
|
|
|
|
* @param {string} normalizedQuery
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2024-07-27 20:56:07 +02:00
|
|
|
matchExpression(column, normalizedQuery) {
|
|
|
|
const normalizedPattern = this.sequelize.escape(`%${normalizedQuery}%`)
|
2024-08-09 23:41:52 +02:00
|
|
|
const normalizedColumn = column
|
2024-07-27 20:56:07 +02:00
|
|
|
return `${normalizedColumn} LIKE ${normalizedPattern}`
|
|
|
|
}
|
2023-07-05 01:14:44 +02:00
|
|
|
}
|
|
|
|
|
2024-06-22 23:42:13 +02:00
|
|
|
module.exports = new Database()
|