QueryBuilder
-
Given a
ForumPost
,Forum
, orCategory
query, adds filters to the query to filter out entities in categories the current user cannot see. Joins the Category (and the Forum, if necessary) to the query to do this.Declaration
Swift
@discardableResult func categoryAccessFilter(for possibleUser: UserCacheData?) -> <<error type>>
-
Uses Postgres full text search capabilities for improved search when using a Postgres db. This fn is modeled after the many filter() methods in FluentKit’s QueryBuilder+Filter.swift.
Declaration
Swift
@discardableResult public func fullTextFilter<Field>(_ field: KeyPath<Model, Field>, _ value: String) -> Self where Field: QueryableProperty, Field.Model == Model, Field.Value == String
-
Declaration
Swift
@discardableResult public func fullTextFilter<Joined, Field>( _ joined: Joined.Type, _ field: KeyPath<Joined, Field>, _ value: String ) -> Self where Joined: Schema, Field: QueryableProperty, Field.Model == Joined, Field.Value == String
-
Joins a foriegn table to the current query and attaches filter clauses to the join. This lets us do the fairly common pattern
Query on <ModelX> and left join <ModelX_Favorite>, filtering the join for the current user's favorites
This returns ModelX rows that nobody has favorited and ModelX rows that others have favorited but the current user hasn’t–with Favorite cols set to nil in each case.Declaration
Swift
@discardableResult func joinWithFilter<LocalField, Foreign, ForeignField>(method: DatabaseQuery.Join.Method = .inner, from: KeyPath<Model, LocalField>, to: KeyPath<Foreign, ForeignField>, otherFilters: [DatabaseQuery.Filter]) -> Self where Foreign: Schema, ForeignField: QueryableProperty, LocalField: QueryableProperty, ForeignField.Value == LocalField.Value
-
Prints an approximation of the SQL this QueryBuilder will produce when run.
Does not produce a fully valid SQL statement because parts of the query aren’t known until.all()
,.count()
,.first()
etc. are called. Also, Fluent may add more clauses to the query when it’s executed, such as the soft-delete filter. The intended purpose of this method is to make it easier to build queries by letting you see what a query is going to look like before executing it.You can see something closer to the actual SQL produced by setting
application.logger.logLevel = .debug
, although this logs everything and is pretty verbose. Also it actually executes the queries, which may be bad if you’ just want to preview the generated SQL.To use: add
query.debugRawSQL()
to your code, wherequery
is aQueryBuilder
. Debug only; don’t check in code that uses this.Declaration
Swift
func debugRawSQL()
-
Copied from file
See morePostgresConverterDelegate.swift
in packagefluent-postgres-driver
to make it available here for debuggingDeclaration
Swift
private struct PostgresConverterDelegate : SQLConverterDelegate
-
Copied from file
See morePostgresConverterDelegate.swift
in packagefluent-postgres-driver
to make it available here for debuggingDeclaration
Swift
private struct SQLArrayDataType : SQLExpression