Enumeration
RawSQLQueries
public enum RawSQLQueries
Object that generates raw SQL.
Note
I wanted to get enough information in one query. The reason for using raw query is that the following function was not found in Fluent.
-
Sub query
-
GROUP_CONCAT(MySQL Only)
-
Distinct
-
DELETE JOIN
-
exists
I may have missed it. As an aside, I have never met OR-Mapper, which can cover the vast specifications of SQL. This is part of the reason, I attach importance to portability over typeSafe for OR-Mapper. There is also a growing need to adopt KVS. Database that interacts directly with the application.
Methods
selectArticles(condition:readIt:offset:limit:)
public static func selectArticles(condition: ArticleCondition, readIt userId: Int?, offset: Int? = nil, limit: Int? = nil) -> String
Returns the query. Inquires about articles according to the argument conditions.
Parameters
Name | Type | Description |
---|---|---|
condition | ArticleCondition |
Information that shows what criteria to search for articles. |
userId | Int? |
ID of the user reading this article. If nil, following is false. |
offset | Int? |
Search result offset. Nil is not set. |
limit | Int? |
Search result limit. Nil is unlimited. |
Returns
SQL query string.
deleteArticles(slug:)
public static func deleteArticles(slug: String) -> String
Returns the query. It deletes an article and related tags and favorite information.
Parameters
Name | Type | Description |
---|---|---|
slug | String |
Article's slug for delete. |
Returns
SQL query string.
selectUser(name:follower:)
public static func selectUser(name: String, follower id: Int?) -> String
Returns the query. Inquiries about users and their follow-up information.
Parameters
Name | Type | Description |
---|---|---|
name | String |
Username to search for. |
id | Int? |
User's ID searching for the user. If nil, following is false. |
Returns
SQL query string.
selectUser(id:follower:)
public static func selectUser(id userId: Int, follower id: Int?) -> String
Returns the query. Inquiries about users and their follow-up information.
Parameters
Name | Type | Description |
---|---|---|
userId | Int |
User's ID to search for. |
id | Int |
User's ID searching for the user. If nil, following is false. |
Returns
SQL query string.
selectComments(for:readIt:)
public static func selectComments(for articleSlug: String, readIt userId: Int? = nil) -> String
Returns the query. Get comments associated with an article.
Parameters
Name | Type | Description |
---|---|---|
articleSlug | String |
Article's slug to be commented. |
userId | Int? |
User who gets the comment. If nil, following is false. |
Returns
SQL query string.
insertComments(for:body:author:)
public static func insertComments(for articleSlug: String, body: String, author userId: Int ) -> String
Returns the query. Inserts a comment associated with an article.
Parameters
Name | Type | Description |
---|---|---|
articleSlug | String |
Article's slug to be commented. |
body | String |
A comment body. |
userId | Int |
User's ID to comment. |
Returns
SQL query string.
deleteComments(id:)
public static func deleteComments(id commentId: Int ) -> String
Returns the query. Delete the comment.
Parameters
Name | Type | Description |
---|---|---|
commentId | Int |
Comment ID for delete. |
Returns
SQL query string.
insertFollows(followee:follower:)
public static func insertFollows(followee username: String, follower id: Int) -> String
Returns the query. Insert follow information associated with a user.
Parameters
Name | Type | Description |
---|---|---|
username | String |
Username to be followed. |
id | Int |
User's Id to follow. |
Returns
SQL query string.
deleteFollows(followee:follower:)
public static func deleteFollows(followee username: String, follower id: Int) -> String
Returns the query. Delete follow information associated with a user.
Parameters
Name | Type | Description |
---|---|---|
username | String |
Username to be unfollowed. |
id | Int |
User's Id to unfollow. |
Returns
SQL query string.
insertFavorites(for:by:)
public static func insertFavorites(for articleSlug: String, by userId: Int) -> String
Returns the query. Inserts favorite information associated with an article.
Parameters
Name | Type | Description |
---|---|---|
articleSlug | String |
Article's slug to be favorited. |
userId | Int |
User's Id to favorite. |
Returns
SQL query string.
deleteFavorites(for:by:)
public static func deleteFavorites(for articleSlug: String, by userId: Int) -> String
Returns the query. This deletes favorite information associated with an article.
Parameters
Name | Type | Description |
---|---|---|
articleSlug | String |
|
userId | Int |
|
Returns
SQL query string.
selectTags()
public static func selectTags() -> String
Returns the query. It returns the tag registered in the database as unique.
Returns
SQL query string.