+
+function searchAttribute (sourceField?: string, targetField?: string) {
+ if (!sourceField) return {}
+
+ return {
+ [targetField]: {
+ // FIXME: ts error
+ [Op.iLike as any]: `%${sourceField}%`
+ }
+ }
+}
+
+function buildSQLAttributes <M extends Model> (options: {
+ model: ModelStatic<M>
+ tableName: string
+
+ excludeAttributes?: Exclude<keyof AttributesOnly<M>, symbol>[]
+ aliasPrefix?: string
+}) {
+ const { model, tableName, aliasPrefix, excludeAttributes } = options
+
+ const attributes = Object.keys(model.getAttributes()) as Exclude<keyof AttributesOnly<M>, symbol>[]
+
+ return attributes
+ .filter(a => {
+ if (!excludeAttributes) return true
+ if (excludeAttributes.includes(a)) return false
+
+ return true
+ })
+ .map(a => {
+ return `"${tableName}"."${a}" AS "${aliasPrefix || ''}${a}"`
+ })
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ buildSQLAttributes,
+ buildBlockedAccountSQL,
+ buildLocalActorIdsIn,
+ getPlaylistSort,
+ SortType,
+ buildLocalAccountIdsIn,
+ getSort,
+ getCommentSort,
+ getAdminUsersSort,
+ getVideoSort,
+ getBlacklistSort,
+ getChannelSyncSort,
+ createSimilarityAttribute,
+ throwIfNotValid,
+ buildServerIdsFollowedBy,
+ buildTrigramSearchIndex,
+ buildWhereIdOrUUID,
+ isOutdated,
+ parseAggregateResult,
+ getInstanceFollowsSort,
+ buildDirectionAndField,
+ createSafeIn,
+ searchAttribute,
+ parseRowCountResult
+}
+
+// ---------------------------------------------------------------------------
+
+function searchTrigramNormalizeValue (value: string) {
+ return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', value))
+}
+
+function searchTrigramNormalizeCol (col: string) {
+ return Sequelize.fn('lower', Sequelize.fn('immutable_unaccent', Sequelize.col(col)))
+}