mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Merge pull request #723 from groue/dev/SE-0255
SE-0255: Implicit returns from single-expression functions
This commit is contained in:
173 files changed
+1004
-1221
No files matched your search
@@ -94,6 +94,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception:
|
||||
- [#720](https://github.com/groue/GRDB.swift/pull/720): Turn deprecated APIs into unavailable ones
|
||||
- [#721](https://github.com/groue/GRDB.swift/pull/721): SE-0249: Key Path Expressions as Functions
|
||||
- [#722](https://github.com/groue/GRDB.swift/pull/722): SE-0253: Callable values of user-defined nominal types
|
||||
- [#723](https://github.com/groue/GRDB.swift/pull/723): SE-0255: Implicit returns from single-expression functions
|
||||
|
||||
|
||||
## 4.11.0
|
||||
|
||||
@@ -91,14 +91,14 @@ With GRDB associations, we can streamline these operations (and others), by decl
|
||||
extension Author {
|
||||
static let books = hasMany(Book.self)
|
||||
var books: QueryInterfaceRequest<Book> {
|
||||
return request(for: Author.books)
|
||||
request(for: Author.books)
|
||||
}
|
||||
}
|
||||
|
||||
extension Book {
|
||||
static let author = belongsTo(Author.self)
|
||||
var author: QueryInterfaceRequest<Author> {
|
||||
return request(for: Book.author)
|
||||
request(for: Book.author)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -165,7 +165,7 @@ Generally speaking, associations use the [TableRecord], [FetchableRecord], and [
|
||||
extension Book: EncodableRecord {
|
||||
// The request for the author of a book.
|
||||
var author: QueryInterfaceRequest<Author> {
|
||||
return request(for: Book.author)
|
||||
request(for: Book.author)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ As in the examples above, **HasManyThrough** association is always built from tw
|
||||
```swift
|
||||
struct Document: TableRecord {
|
||||
static let paragraphs = hasMany(
|
||||
Paragraph.self,
|
||||
Paragraph.self,
|
||||
through: Document.hasMany(Section.self),
|
||||
using: Section.hasMany(Paragraph.self))
|
||||
...
|
||||
@@ -785,7 +785,7 @@ struct Book: TableRecord, EncodableRecord {
|
||||
|
||||
/// The request for the author of a book
|
||||
var author: QueryInterfaceRequest<Author> {
|
||||
return request(for: Book.author)
|
||||
request(for: Book.author)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -806,7 +806,7 @@ struct Author: TableRecord, EncodableRecord {
|
||||
|
||||
/// The request for the books of an author
|
||||
var books: QueryInterfaceRequest<Book> {
|
||||
return request(for: Author.books)
|
||||
request(for: Author.books)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1140,7 +1140,7 @@ extension Team {
|
||||
static let players = hasMany(Player.self).order(Column("position"))
|
||||
|
||||
var players: QueryInterfaceRequest<Player> {
|
||||
return request(for: Team.players)
|
||||
request(for: Team.players)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1174,7 +1174,7 @@ extension Team {
|
||||
static let players = hasMany(Player.self, through: playerRoles, using: PlayerRole.player)
|
||||
|
||||
var players: QueryInterfaceRequest<Player> {
|
||||
return request(for: Team.players)
|
||||
request(for: Team.players)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1383,7 +1383,7 @@ For example, we can start by defining base requests as extensions to the [Deriva
|
||||
extension DerivableRequest where RowDecoder == Author {
|
||||
/// Filters authors by country
|
||||
func filter(country: String) -> Self {
|
||||
return filter(Column("country") == country)
|
||||
filter(Column("country") == country)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1391,7 +1391,7 @@ extension DerivableRequest where RowDecoder == Author {
|
||||
extension DerivableRequest where RowDecoder == Book {
|
||||
/// Filters books by author country
|
||||
func filter(authorCountry: String) -> Self {
|
||||
return joining(required: Book.author.filter(country: country))
|
||||
joining(required: Book.author.filter(country: country))
|
||||
}
|
||||
|
||||
/// Order books by author name and then book title
|
||||
@@ -1610,8 +1610,7 @@ And who is the most able to know those coding keys? BookInfo itself, thanks to i
|
||||
```swift
|
||||
extension BookInfo {
|
||||
static func all() -> QueryInterfaceRequest<BookInfo> {
|
||||
return Book
|
||||
.including(optional: Book.coverImage)
|
||||
Book.including(optional: Book.coverImage)
|
||||
.including(required: Book.author
|
||||
.forKey(CodingKeys.authorInfo) // (1)
|
||||
.including(optional: Person.country))
|
||||
@@ -1758,7 +1757,7 @@ When you need to compute aggregates **from a single record**, you use [regular a
|
||||
struct Author: TableRecord, EncodableRecord {
|
||||
static let books = hasMany(Book.self)
|
||||
var books: QueryInterfaceRequest<Book> {
|
||||
return request(for: Author.books)
|
||||
request(for: Author.books)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2306,17 +2305,17 @@ Those methods are defined on extensions to the `DerivableRequest` protocol:
|
||||
```swift
|
||||
extension DerivableRequest where RowDecoder == Author {
|
||||
func filter(country: String) -> Self {
|
||||
return filter(Column("country") == country)
|
||||
filter(Column("country") == country)
|
||||
}
|
||||
|
||||
func orderedByName() -> Self {
|
||||
return order(Column("name").collating(.localizedCaseInsensitiveCompare))
|
||||
order(Column("name").collating(.localizedCaseInsensitiveCompare))
|
||||
}
|
||||
}
|
||||
|
||||
extension DerivableRequest where RowDecoder == Book {
|
||||
func filter(country: String) -> Self {
|
||||
return joining(required: Book.author.filter(country: country))
|
||||
joining(required: Book.author.filter(country: country))
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -35,11 +35,11 @@ extension Player: Codable, FetchableRecord, MutablePersistableRecord {
|
||||
// See https://github.com/groue/GRDB.swift/blob/master/README.md#requests
|
||||
extension Player {
|
||||
static func orderedByName() -> QueryInterfaceRequest<Player> {
|
||||
return Player.order(Columns.name)
|
||||
Player.order(Columns.name)
|
||||
}
|
||||
|
||||
static func orderedByScore() -> QueryInterfaceRequest<Player> {
|
||||
return Player.order(Columns.score.desc, Columns.name)
|
||||
Player.order(Columns.score.desc, Columns.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,10 +57,10 @@ extension Player {
|
||||
"Zazie", "Zoé"]
|
||||
|
||||
static func randomName() -> String {
|
||||
return names.randomElement()!
|
||||
names.randomElement()!
|
||||
}
|
||||
|
||||
static func randomScore() -> Int {
|
||||
return 10 * Int.random(in: 0...100)
|
||||
10 * Int.random(in: 0...100)
|
||||
}
|
||||
}
|
||||
@@ -174,7 +174,7 @@ extension PlayersViewController {
|
||||
|
||||
extension PlayersViewController {
|
||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return players.count
|
||||
players.count
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
|
||||
@@ -313,7 +313,7 @@ final class SynonymsTokenizer : FTS5WrapperTokenizer {
|
||||
}
|
||||
|
||||
func synonyms(for token: String) -> Set<String>? {
|
||||
return synonyms.first { $0.contains(token) }
|
||||
synonyms.first { $0.contains(token) }
|
||||
}
|
||||
|
||||
func accept(token: String, flags: FTS5TokenFlags, for tokenization: FTS5Tokenization, tokenCallback: FTS5WrapperTokenCallback) throws {
|
||||
|
||||
@@ -227,11 +227,11 @@ The table view data source asks the fetched records controller to provide releva
|
||||
|
||||
```swift
|
||||
func numberOfSections(in tableView: UITableView) -> Int {
|
||||
return fetchedRecordsController.sections.count
|
||||
fetchedRecordsController.sections.count
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
return fetchedRecordsController.sections[section].numberOfRecords
|
||||
fetchedRecordsController.sections[section].numberOfRecords
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
|
||||
@@ -197,7 +197,7 @@ extension DerivableRequest where RowDecoder == Author {
|
||||
|
||||
/// Returns a request for all authors from a country
|
||||
func filter(country: String) -> Self {
|
||||
return filter(Author.Columns.country == country)
|
||||
filter(Author.Columns.country == country)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -231,7 +231,7 @@ extension DerivableRequest where RowDecoder == Book {
|
||||
// A book is from a country if it can be
|
||||
// joined with an author from that country:
|
||||
// ---------------------------------v
|
||||
return joining(required: Book.author.filter(country: authorCountry))
|
||||
self.joining(required: Book.author.filter(country: authorCountry))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ Not *every requests* can be expressed on `DerivableRequest`. For example, [Assoc
|
||||
extension QueryInterfaceRequest where RowDecoder == Author {
|
||||
/// Returns a request for all authors with at least one book
|
||||
func havingBooks() -> QueryInterfaceRequest<Author> {
|
||||
return having(Author.books.isEmpty == false)
|
||||
having(Author.books.isEmpty == false)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -388,14 +388,14 @@ A last extension on your record types will further help navigation from records
|
||||
extension Author {
|
||||
/// The request for the author's books
|
||||
var books: QueryInterfaceRequest<Book> {
|
||||
return request(for: Author.books)
|
||||
request(for: Author.books)
|
||||
}
|
||||
}
|
||||
|
||||
extension Book {
|
||||
/// The request for the author of the book
|
||||
var author: QueryInterfaceRequest<Author> {
|
||||
return request(for: Book.author)
|
||||
request(for: Book.author)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -530,19 +530,19 @@ class ImprovedLibraryManager {
|
||||
}
|
||||
|
||||
func author(id: Int64) throws -> Author? {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
try Author.fetchOne(db, key: id)
|
||||
}
|
||||
}
|
||||
|
||||
func book(id: Int64) throws -> Book? {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
try Book.fetchOne(db, key: id)
|
||||
}
|
||||
}
|
||||
|
||||
func books(writtenBy author: Author) throws -> [Book] {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
try author.books.fetchAll(db)
|
||||
}
|
||||
}
|
||||
@@ -593,7 +593,7 @@ extension LibraryManager {
|
||||
}
|
||||
|
||||
func authorList() throws -> [AuthorListItem] {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
let request = Author
|
||||
.annotated(with: Author.books.count)
|
||||
.orderByName()
|
||||
@@ -610,7 +610,7 @@ extension LibraryManager {
|
||||
}
|
||||
|
||||
func bookInfo(bookId: Int64) throws -> BookInfo? {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
guard let book = try Book.fetchOne(db, key: bookId) else {
|
||||
return nil
|
||||
}
|
||||
@@ -630,7 +630,7 @@ extension LibraryManager {
|
||||
}
|
||||
|
||||
func authorInfo(authorId: Int64) throws -> AuthorInfo? {
|
||||
return try dbQueue.read { db in
|
||||
try dbQueue.read { db in
|
||||
guard let author = try Author.fetchOne(db, key: authorId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -61,16 +61,12 @@ struct Book: Codable, FetchableRecord, MutablePersistableRecord {
|
||||
|
||||
extension Author {
|
||||
static let books = hasMany(Book.self)
|
||||
var books: QueryInterfaceRequest<Book> {
|
||||
return request(for: Author.books)
|
||||
}
|
||||
var books: QueryInterfaceRequest<Book> { request(for: Author.books) }
|
||||
}
|
||||
|
||||
extension Book {
|
||||
static let author = belongsTo(Author.self)
|
||||
var author: QueryInterfaceRequest<Author> {
|
||||
return request(for: Book.author)
|
||||
}
|
||||
var author: QueryInterfaceRequest<Author> { request(for: Book.author) }
|
||||
}
|
||||
|
||||
//: Populate the database
|
||||
|
||||
+12
-12
@@ -47,13 +47,13 @@ import GRDB
|
||||
//: Everything starts from our class hierarchy:
|
||||
|
||||
class Base {
|
||||
var description: String { return "Base" }
|
||||
var description: String { "Base" }
|
||||
init() { }
|
||||
}
|
||||
|
||||
class Foo: Base {
|
||||
var name: String
|
||||
override var description: String { return "Foo: \(name)" }
|
||||
override var description: String { "Foo: \(name)" }
|
||||
init(name: String) {
|
||||
self.name = name
|
||||
super.init()
|
||||
@@ -62,7 +62,7 @@ class Foo: Base {
|
||||
|
||||
class Bar: Base {
|
||||
var score: Int
|
||||
override var description: String { return "Bar: \(score)" }
|
||||
override var description: String { "Bar: \(score)" }
|
||||
init(score: Int) {
|
||||
self.score = score
|
||||
super.init()
|
||||
@@ -302,15 +302,15 @@ extension FetchRequest where RowDecoder: MyDatabaseDecoder {
|
||||
// MARK: - FetchRequest fetching methods
|
||||
|
||||
func fetchCursor(_ db: Database) throws -> MapCursor<RowCursor, RowDecoder.DecodedType> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
func fetchAll(_ db: Database) throws -> [RowDecoder.DecodedType] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
func fetchOne(_ db: Database) throws -> RowDecoder.DecodedType? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -335,15 +335,15 @@ extension MyDatabaseDecoder where Self: TableRecord {
|
||||
// MARK: - Static fetching methods
|
||||
|
||||
static func fetchCursor(_ db: Database) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
return try all().fetchCursor(db)
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
static func fetchAll(_ db: Database) throws -> [DecodedType] {
|
||||
return try all().fetchAll(db)
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
static func fetchOne(_ db: Database) throws -> DecodedType? {
|
||||
return try all().fetchOne(db)
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,15 +366,15 @@ extension MyDatabaseDecoder {
|
||||
// MARK: - Fetch from SQL
|
||||
|
||||
static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor<RowCursor, DecodedType> {
|
||||
return try fetchCursor(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
try fetchCursor(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
|
||||
static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] {
|
||||
return try fetchAll(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
try fetchAll(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
|
||||
static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? {
|
||||
return try fetchOne(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
try fetchOne(db, SQLRequest<Void>(sql: sql, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ class TestDeleteAll: NSObject {
|
||||
struct MyRecord: FetchableRecord, TableRecord, PersistableRecord {
|
||||
|
||||
static let MyColumn = Column("MyColumn")
|
||||
static var databaseTableName: String { return String(describing: self) }
|
||||
static var databaseTableName: String { String(describing: self) }
|
||||
|
||||
let myColumn: String
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ try! migrator.migrate(dbQueue)
|
||||
class TableChangeObserver : NSObject, TransactionObserver {
|
||||
private var changedTableNames: Set<String> = []
|
||||
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
|
||||
return true
|
||||
}
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { true }
|
||||
|
||||
func databaseDidChange(with event: DatabaseEvent) {
|
||||
changedTableNames.insert(event.tableName)
|
||||
|
||||
@@ -184,25 +184,25 @@ extension Player: Decodable, FetchableRecord, TableRecord {
|
||||
|
||||
/// The player with a given id
|
||||
static func filter(id: Int64) -> SQLRequest<Player> {
|
||||
return "SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)"
|
||||
"SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)"
|
||||
}
|
||||
|
||||
/// All players with the given ids
|
||||
static func filter(ids: [Int64]) -> SQLRequest<Player> {
|
||||
return "SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)"
|
||||
"SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)"
|
||||
}
|
||||
|
||||
/// The maximum score
|
||||
static func maximumScore() -> SQLRequest<Int> {
|
||||
return "SELECT MAX(\(CodingKeys.score)) FROM \(self)"
|
||||
"SELECT MAX(\(CodingKeys.score)) FROM \(self)"
|
||||
}
|
||||
|
||||
/// All players whose score is the maximum score
|
||||
static func leaders() -> SQLRequest<Player> {
|
||||
return """
|
||||
SELECT * FROM \(self)
|
||||
WHERE \(CodingKeys.score) = \(maximumScore())
|
||||
"""
|
||||
"""
|
||||
SELECT * FROM \(self)
|
||||
WHERE \(CodingKeys.score) = \(maximumScore())
|
||||
"""
|
||||
}
|
||||
|
||||
/// A complex request
|
||||
@@ -247,7 +247,7 @@ Let's breakdown each one of those methods.
|
||||
extension Player: Decodable, FetchableRecord, TableRecord {
|
||||
/// The player with a given id
|
||||
static func filter(id: Int64) -> SQLRequest<Player> {
|
||||
return "SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)"
|
||||
"SELECT * FROM \(self) WHERE \(CodingKeys.id) = \(id)"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -271,7 +271,7 @@ Let's breakdown each one of those methods.
|
||||
extension Player: Decodable, FetchableRecord, TableRecord {
|
||||
/// All players with the given ids
|
||||
static func filter(ids: [Int64]) -> SQLRequest<Player> {
|
||||
return "SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)"
|
||||
"SELECT * FROM \(self) WHERE \(CodingKeys.id) IN \(ids)"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -293,7 +293,7 @@ Let's breakdown each one of those methods.
|
||||
extension Player: Decodable, FetchableRecord, TableRecord {
|
||||
/// The maximum score
|
||||
static func maximumScore() -> SQLRequest<Int> {
|
||||
return "SELECT MAX(\(CodingKeys.score)) FROM \(self)"
|
||||
"SELECT MAX(\(CodingKeys.score)) FROM \(self)"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -315,10 +315,10 @@ Let's breakdown each one of those methods.
|
||||
extension Player: Decodable, FetchableRecord, TableRecord {
|
||||
/// All players whose score is the maximum score
|
||||
static func leaders() -> SQLRequest<Player> {
|
||||
return """
|
||||
SELECT * FROM \(self)
|
||||
WHERE \(CodingKeys.score) = \(maximumScore())
|
||||
"""
|
||||
"""
|
||||
SELECT * FROM \(self)
|
||||
WHERE \(CodingKeys.score) = \(maximumScore())
|
||||
"""
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -246,7 +246,7 @@ try db.execute(literal: "UPDATE player SET score = \(score) WHERE id = \(id)")
|
||||
|
||||
extension Player {
|
||||
static func filter(name: String) -> SQLRequest<Player> {
|
||||
return "SELECT * FROM \(self) WHERE \(CodingKeys.name) = \(name)"
|
||||
"SELECT * FROM player WHERE name = \(name)"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -92,7 +92,7 @@ extension Cursor {
|
||||
/// Returns a Boolean value indicating whether the cursor contains
|
||||
/// an element.
|
||||
public func isEmpty() throws -> Bool {
|
||||
return try next() == nil
|
||||
try next() == nil
|
||||
}
|
||||
|
||||
/// Returns a Boolean value indicating whether the cursor contains an
|
||||
@@ -123,12 +123,12 @@ extension Cursor {
|
||||
/// // Prints: "0: foo"
|
||||
/// // Prints: "1: bar"
|
||||
public func enumerated() -> EnumeratedCursor<Self> {
|
||||
return EnumeratedCursor(self)
|
||||
EnumeratedCursor(self)
|
||||
}
|
||||
|
||||
/// Returns the elements of the cursor that satisfy the given predicate.
|
||||
public func filter(_ isIncluded: @escaping (Element) throws -> Bool) -> FilterCursor<Self> {
|
||||
return FilterCursor(self, isIncluded)
|
||||
FilterCursor(self, isIncluded)
|
||||
}
|
||||
|
||||
/// Returns the first element of the cursor that satisfies the given
|
||||
@@ -158,7 +158,7 @@ extension Cursor {
|
||||
/// `false` otherwise. Once `predicate` returns `false` it will not be
|
||||
/// called again.
|
||||
public func drop(while predicate: @escaping (Element) throws -> Bool) -> DropWhileCursor<Self> {
|
||||
return DropWhileCursor(self, predicate: predicate)
|
||||
DropWhileCursor(self, predicate: predicate)
|
||||
}
|
||||
|
||||
/// Returns a cursor containing all but the given number of initial
|
||||
@@ -178,7 +178,7 @@ extension Cursor {
|
||||
/// - Returns: A cursor starting after the specified number of
|
||||
/// elements.
|
||||
public func dropFirst(_ n: Int) -> DropFirstCursor<Self> {
|
||||
return DropFirstCursor(self, limit: n)
|
||||
DropFirstCursor(self, limit: n)
|
||||
}
|
||||
|
||||
/// Returns a cursor containing all but the first element of the cursor.
|
||||
@@ -193,7 +193,7 @@ extension Cursor {
|
||||
///
|
||||
/// - Returns: A cursor starting after the first element of the cursor.
|
||||
public func dropFirst() -> DropFirstCursor<Self> {
|
||||
return dropFirst(1)
|
||||
dropFirst(1)
|
||||
}
|
||||
|
||||
/// Returns an array containing all but the given number of final
|
||||
@@ -243,7 +243,7 @@ extension Cursor {
|
||||
///
|
||||
/// - Returns: An array leaving off the last element of the cursor.
|
||||
public func dropLast() throws -> [Element] {
|
||||
return try dropLast(1)
|
||||
try dropLast(1)
|
||||
}
|
||||
|
||||
/// Returns a cursor over the concatenated results of mapping transform
|
||||
@@ -274,7 +274,7 @@ extension Cursor {
|
||||
/// Returns a cursor over the results of the transform function applied to
|
||||
/// this cursor's elements.
|
||||
public func map<T>(_ transform: @escaping (Element) throws -> T) -> MapCursor<Self, T> {
|
||||
return MapCursor(self, transform)
|
||||
MapCursor(self, transform)
|
||||
}
|
||||
|
||||
/// Returns the maximum element in the cursor, using the given predicate as
|
||||
@@ -334,7 +334,7 @@ extension Cursor {
|
||||
/// - Returns: A cursor starting at the beginning of this cursor
|
||||
/// with at most `maxLength` elements.
|
||||
public func prefix(_ maxLength: Int) -> PrefixCursor<Self> {
|
||||
return PrefixCursor(self, maxLength: maxLength)
|
||||
PrefixCursor(self, maxLength: maxLength)
|
||||
}
|
||||
|
||||
/// Returns a cursor of the initial consecutive elements that satisfy
|
||||
@@ -345,7 +345,7 @@ extension Cursor {
|
||||
/// `false` otherwise. Once `predicate` returns `false` it will not be
|
||||
/// called again.
|
||||
public func prefix(while predicate: @escaping (Element) throws -> Bool) -> PrefixWhileCursor<Self> {
|
||||
return PrefixWhileCursor(self, predicate: predicate)
|
||||
PrefixWhileCursor(self, predicate: predicate)
|
||||
}
|
||||
|
||||
/// Returns the result of calling the given combining closure with each
|
||||
@@ -448,7 +448,7 @@ extension Cursor where Element: Comparable {
|
||||
/// `areInIncreasingOrder`. If the cursor has no elements, returns
|
||||
/// `nil`.
|
||||
public func max() throws -> Element? {
|
||||
return try max(by: <)
|
||||
try max(by: <)
|
||||
}
|
||||
|
||||
/// Returns the minimum element in the cursor.
|
||||
@@ -460,7 +460,7 @@ extension Cursor where Element: Comparable {
|
||||
/// `areInIncreasingOrder`. If the cursor has no elements, returns
|
||||
/// `nil`.
|
||||
public func min() throws -> Element? {
|
||||
return try min(by: <)
|
||||
try min(by: <)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ extension Cursor where Element: Comparable {
|
||||
extension Cursor where Element: Cursor {
|
||||
/// Returns the elements of this cursor of cursors, concatenated.
|
||||
public func joined() -> FlattenCursor<Self> {
|
||||
return FlattenCursor(self)
|
||||
FlattenCursor(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,7 +478,7 @@ extension Cursor where Element: Cursor {
|
||||
extension Cursor where Element: Sequence {
|
||||
/// Returns the elements of this cursor of sequences, concatenated.
|
||||
public func joined() -> FlattenCursor<MapCursor<Self, AnyCursor<Element.Element>>> {
|
||||
return flatMap { $0 }
|
||||
flatMap { $0 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ public final class AnyCursor<Element>: Cursor {
|
||||
/// element exists.
|
||||
/// :nodoc:
|
||||
public func next() throws -> Element? {
|
||||
return try element()
|
||||
try element()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ extension Database {
|
||||
|
||||
/// Returns whether a table exists.
|
||||
public func tableExists(_ name: String) throws -> Bool {
|
||||
return try exists(type: .table, name: name)
|
||||
try exists(type: .table, name: name)
|
||||
}
|
||||
|
||||
/// Returns whether a table is an internal SQLite table.
|
||||
@@ -50,17 +50,17 @@ extension Database {
|
||||
///
|
||||
/// Those are tables whose name begins with "grdb_".
|
||||
public func isGRDBInternalTable(_ tableName: String) -> Bool {
|
||||
return tableName.starts(with: "grdb_")
|
||||
tableName.starts(with: "grdb_")
|
||||
}
|
||||
|
||||
/// Returns whether a view exists.
|
||||
public func viewExists(_ name: String) throws -> Bool {
|
||||
return try exists(type: .view, name: name)
|
||||
try exists(type: .view, name: name)
|
||||
}
|
||||
|
||||
/// Returns whether a trigger exists.
|
||||
public func triggerExists(_ name: String) throws -> Bool {
|
||||
return try exists(type: .trigger, name: name)
|
||||
try exists(type: .trigger, name: name)
|
||||
}
|
||||
|
||||
private func exists(type: SchemaObjectType, name: String) throws -> Bool {
|
||||
@@ -531,7 +531,7 @@ public struct PrimaryKeyInfo {
|
||||
private let impl: Impl
|
||||
|
||||
static func rowID(_ column: String) -> PrimaryKeyInfo {
|
||||
return PrimaryKeyInfo(impl: .rowID(column))
|
||||
PrimaryKeyInfo(impl: .rowID(column))
|
||||
}
|
||||
|
||||
static func regular(_ columns: [String]) -> PrimaryKeyInfo {
|
||||
@@ -589,12 +589,12 @@ public struct ForeignKeyInfo {
|
||||
|
||||
/// The origin columns
|
||||
public var originColumns: [String] {
|
||||
return mapping.map(\.origin)
|
||||
mapping.map(\.origin)
|
||||
}
|
||||
|
||||
/// The destination columns
|
||||
public var destinationColumns: [String] {
|
||||
return mapping.map(\.destination)
|
||||
mapping.map(\.destination)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ struct SchemaInfo: Equatable {
|
||||
|
||||
/// All names for a given type
|
||||
func names(ofType type: SchemaObjectType) -> Set<String> {
|
||||
return objects.reduce(into: []) { (set, key) in
|
||||
objects.reduce(into: []) { (set, key) in
|
||||
if key.type == type.rawValue {
|
||||
set.insert(key.name)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ extension Database {
|
||||
/// - returns: A SelectStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func makeSelectStatement(sql: String) throws -> SelectStatement {
|
||||
return try makeSelectStatement(sql: sql, prepFlags: 0)
|
||||
try makeSelectStatement(sql: sql, prepFlags: 0)
|
||||
}
|
||||
|
||||
/// Returns a new prepared statement that can be reused.
|
||||
@@ -36,7 +36,7 @@ extension Database {
|
||||
/// - returns: A SelectStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
func makeSelectStatement(sql: String, prepFlags: Int32) throws -> SelectStatement {
|
||||
return try SelectStatement.prepare(self, sql: sql, prepFlags: prepFlags)
|
||||
try SelectStatement.prepare(self, sql: sql, prepFlags: prepFlags)
|
||||
}
|
||||
|
||||
/// Returns a prepared statement that can be reused.
|
||||
@@ -52,12 +52,12 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func cachedSelectStatement(sql: String) throws -> SelectStatement {
|
||||
return try publicStatementCache.selectStatement(sql)
|
||||
try publicStatementCache.selectStatement(sql)
|
||||
}
|
||||
|
||||
/// Returns a cached statement that does not conflict with user's cached statements.
|
||||
func internalCachedSelectStatement(sql: String) throws -> SelectStatement {
|
||||
return try internalStatementCache.selectStatement(sql)
|
||||
try internalStatementCache.selectStatement(sql)
|
||||
}
|
||||
|
||||
/// Returns a new prepared statement that can be reused.
|
||||
@@ -70,7 +70,7 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func makeUpdateStatement(sql: String) throws -> UpdateStatement {
|
||||
return try makeUpdateStatement(sql: sql, prepFlags: 0)
|
||||
try makeUpdateStatement(sql: sql, prepFlags: 0)
|
||||
}
|
||||
|
||||
/// Returns a new prepared statement that can be reused.
|
||||
@@ -85,7 +85,7 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
func makeUpdateStatement(sql: String, prepFlags: Int32) throws -> UpdateStatement {
|
||||
return try UpdateStatement.prepare(self, sql: sql, prepFlags: prepFlags)
|
||||
try UpdateStatement.prepare(self, sql: sql, prepFlags: prepFlags)
|
||||
}
|
||||
|
||||
/// Returns a prepared statement that can be reused.
|
||||
@@ -101,12 +101,12 @@ extension Database {
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
public func cachedUpdateStatement(sql: String) throws -> UpdateStatement {
|
||||
return try publicStatementCache.updateStatement(sql)
|
||||
try publicStatementCache.updateStatement(sql)
|
||||
}
|
||||
|
||||
/// Returns a cached statement that does not conflict with user's cached statements.
|
||||
func internalCachedUpdateStatement(sql: String) throws -> UpdateStatement {
|
||||
return try internalStatementCache.updateStatement(sql)
|
||||
try internalStatementCache.updateStatement(sql)
|
||||
}
|
||||
|
||||
/// Executes one or several SQL statements, separated by semi-colons.
|
||||
|
||||
@@ -126,10 +126,10 @@ public final class Database {
|
||||
lazy var publicStatementCache = StatementCache(database: self)
|
||||
|
||||
/// The last error code
|
||||
public var lastErrorCode: ResultCode { return ResultCode(rawValue: sqlite3_errcode(sqliteConnection)) }
|
||||
public var lastErrorCode: ResultCode { ResultCode(rawValue: sqlite3_errcode(sqliteConnection)) }
|
||||
|
||||
/// The last error message
|
||||
public var lastErrorMessage: String? { return String(cString: sqlite3_errmsg(sqliteConnection)) }
|
||||
public var lastErrorMessage: String? { String(cString: sqlite3_errmsg(sqliteConnection)) }
|
||||
|
||||
/// Statement authorizer. Use withAuthorizer(_:_:).
|
||||
fileprivate var _authorizer: StatementAuthorizer?
|
||||
|
||||
@@ -20,12 +20,10 @@ public struct ResultCode: RawRepresentable, Equatable, CustomStringConvertible {
|
||||
/// let resultCode = .SQLITE_CONSTRAINT_FOREIGNKEY
|
||||
/// resultCode.primaryResultCode == .SQLITE_CONSTRAINT // true
|
||||
public var primaryResultCode: ResultCode {
|
||||
return ResultCode(rawValue: rawValue & 0xFF)
|
||||
ResultCode(rawValue: rawValue & 0xFF)
|
||||
}
|
||||
|
||||
var isPrimary: Bool {
|
||||
return self == primaryResultCode
|
||||
}
|
||||
var isPrimary: Bool { self == primaryResultCode }
|
||||
|
||||
/// Returns true if the code on the left matches the code on the right.
|
||||
///
|
||||
@@ -159,7 +157,7 @@ public struct ResultCode: RawRepresentable, Equatable, CustomStringConvertible {
|
||||
// CustomStringConvertible
|
||||
extension ResultCode {
|
||||
var errorString: String? {
|
||||
return String(cString: sqlite3_errstr(rawValue))
|
||||
String(cString: sqlite3_errstr(rawValue))
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -190,7 +188,7 @@ public struct DatabaseError: Error, CustomStringConvertible, CustomNSError {
|
||||
///
|
||||
/// See also `extendedResultCode`.
|
||||
public var resultCode: ResultCode {
|
||||
return extendedResultCode.primaryResultCode
|
||||
extendedResultCode.primaryResultCode
|
||||
}
|
||||
|
||||
/// The SQLite extended error code (see
|
||||
@@ -281,19 +279,13 @@ extension DatabaseError {
|
||||
|
||||
/// NSError bridging: the domain of the error.
|
||||
/// :nodoc:
|
||||
public static var errorDomain: String {
|
||||
return "GRDB.DatabaseError"
|
||||
}
|
||||
public static var errorDomain: String { "GRDB.DatabaseError" }
|
||||
|
||||
/// NSError bridging: the error code within the given domain.
|
||||
/// :nodoc:
|
||||
public var errorCode: Int {
|
||||
return Int(extendedResultCode.rawValue)
|
||||
}
|
||||
public var errorCode: Int { Int(extendedResultCode.rawValue) }
|
||||
|
||||
/// NSError bridging: the user-info dictionary.
|
||||
/// :nodoc:
|
||||
public var errorUserInfo: [String: Any] {
|
||||
return [NSLocalizedDescriptionKey: description]
|
||||
}
|
||||
public var errorUserInfo: [String: Any] { [NSLocalizedDescriptionKey: description] }
|
||||
}
|
||||
@@ -14,11 +14,11 @@ public final class DatabaseFunction: Hashable {
|
||||
let nArg: Int32 // -1 for variadic functions
|
||||
}
|
||||
|
||||
public var name: String { return identity.name }
|
||||
public var name: String { identity.name }
|
||||
private let identity: Identity
|
||||
let pure: Bool
|
||||
private let kind: Kind
|
||||
private var eTextRep: Int32 { return (SQLITE_UTF8 | (pure ? SQLITE_DETERMINISTIC : 0)) }
|
||||
private var eTextRep: Int32 { (SQLITE_UTF8 | (pure ? SQLITE_DETERMINISTIC : 0)) }
|
||||
|
||||
/// Returns an SQL function.
|
||||
///
|
||||
@@ -343,7 +343,7 @@ extension DatabaseFunction {
|
||||
/// Two functions are equal if they share the same name and arity.
|
||||
/// :nodoc:
|
||||
public static func == (lhs: DatabaseFunction, rhs: DatabaseFunction) -> Bool {
|
||||
return lhs.identity == rhs.identity
|
||||
lhs.identity == rhs.identity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,14 @@ public final class DatabasePool: DatabaseWriter {
|
||||
|
||||
// MARK: - Database Information
|
||||
|
||||
/// The path to the database.
|
||||
public var path: String {
|
||||
return writer.path
|
||||
/// The database configuration
|
||||
public var configuration: Configuration {
|
||||
writer.configuration
|
||||
}
|
||||
|
||||
public var configuration: Configuration {
|
||||
return writer.configuration
|
||||
/// The path to the database.
|
||||
public var path: String {
|
||||
writer.path
|
||||
}
|
||||
|
||||
// MARK: - Initializer
|
||||
@@ -637,7 +638,7 @@ extension DatabasePool: DatabaseReader {
|
||||
/// - parameter updates: The updates to the database.
|
||||
/// - throws: The error thrown by the updates.
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync(updates)
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
/// Synchronously executes database updates in a protected dispatch queue,
|
||||
@@ -654,7 +655,7 @@ extension DatabasePool: DatabaseReader {
|
||||
/// - parameter updates: The updates to the database.
|
||||
/// - throws: The error thrown by the updates.
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try readerPool.barrier {
|
||||
try readerPool.barrier {
|
||||
try writer.sync(updates)
|
||||
}
|
||||
}
|
||||
@@ -711,7 +712,7 @@ extension DatabasePool: DatabaseReader {
|
||||
/// This method is reentrant. It should be avoided because it fosters
|
||||
/// dangerous concurrency practices.
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.reentrantSync(updates)
|
||||
try writer.reentrantSync(updates)
|
||||
}
|
||||
|
||||
/// Asynchronously executes database updates in a protected dispatch queue,
|
||||
|
||||
@@ -12,12 +12,12 @@ public final class DatabaseQueue: DatabaseWriter {
|
||||
|
||||
/// The database configuration
|
||||
public var configuration: Configuration {
|
||||
return writer.configuration
|
||||
writer.configuration
|
||||
}
|
||||
|
||||
/// The path to the database file; it is ":memory:" for in-memory databases.
|
||||
public var path: String {
|
||||
return writer.path
|
||||
writer.path
|
||||
}
|
||||
|
||||
// MARK: - Initializers
|
||||
@@ -195,7 +195,7 @@ extension DatabaseQueue {
|
||||
/// - parameter block: A block that accesses the database.
|
||||
/// - throws: The error thrown by the block.
|
||||
public func read<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync { db in
|
||||
try writer.sync { db in
|
||||
try db.readOnly { try block(db) }
|
||||
}
|
||||
}
|
||||
@@ -245,7 +245,7 @@ extension DatabaseQueue {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync(block)
|
||||
try writer.sync(block)
|
||||
}
|
||||
|
||||
/// Synchronously executes a block in a protected dispatch queue, and
|
||||
@@ -260,7 +260,7 @@ extension DatabaseQueue {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.reentrantSync(block)
|
||||
try writer.reentrantSync(block)
|
||||
}
|
||||
|
||||
public func concurrentRead<T>(_ block: @escaping (Database) throws -> T) -> DatabaseFuture<T> {
|
||||
@@ -351,7 +351,7 @@ extension DatabaseQueue {
|
||||
/// - parameter updates: The updates to the database.
|
||||
/// - throws: The error thrown by the updates.
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync(updates)
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
/// Synchronously executes database updates in a protected dispatch queue,
|
||||
@@ -365,7 +365,7 @@ extension DatabaseQueue {
|
||||
/// - parameter updates: The updates to the database.
|
||||
/// - throws: The error thrown by the updates.
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync(updates)
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
/// Synchronously executes database updates in a protected dispatch queue,
|
||||
@@ -381,7 +381,7 @@ extension DatabaseQueue {
|
||||
/// - parameter block: A block that accesses the database.
|
||||
/// - throws: The error thrown by the block.
|
||||
public func inDatabase<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.sync(updates)
|
||||
try writer.sync(updates)
|
||||
}
|
||||
|
||||
/// Synchronously executes database updates in a protected dispatch queue, and
|
||||
@@ -395,7 +395,7 @@ extension DatabaseQueue {
|
||||
/// This method is reentrant. It is unsafe because it fosters dangerous
|
||||
/// concurrency practices.
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try writer.reentrantSync(updates)
|
||||
try writer.reentrantSync(updates)
|
||||
}
|
||||
|
||||
/// Asynchronously executes database updates in a protected dispatch queue,
|
||||
|
||||
@@ -308,7 +308,7 @@ public final class AnyDatabaseReader: DatabaseReader {
|
||||
|
||||
/// :nodoc:
|
||||
public var configuration: Configuration {
|
||||
return base.configuration
|
||||
base.configuration
|
||||
}
|
||||
|
||||
// MARK: - Interrupting Database Operations
|
||||
@@ -322,7 +322,7 @@ public final class AnyDatabaseReader: DatabaseReader {
|
||||
|
||||
/// :nodoc:
|
||||
public func read<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.read(block)
|
||||
try base.read(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -332,12 +332,12 @@ public final class AnyDatabaseReader: DatabaseReader {
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeRead(block)
|
||||
try base.unsafeRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeReentrantRead(block)
|
||||
try base.unsafeReentrantRead(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
@@ -170,7 +170,7 @@ extension DatabaseRegion {
|
||||
/// Returns whether the content in the region would be impacted if the
|
||||
/// database were modified by an event of this kind.
|
||||
public func isModified(byEventsOfKind eventKind: DatabaseEventKind) -> Bool {
|
||||
return intersection(eventKind.modifiedRegion).isEmpty == false
|
||||
intersection(eventKind.modifiedRegion).isEmpty == false
|
||||
}
|
||||
|
||||
/// Returns whether the content in the region is impacted by this event.
|
||||
@@ -319,7 +319,7 @@ public protocol DatabaseRegionConvertible {
|
||||
extension DatabaseRegion: DatabaseRegionConvertible {
|
||||
/// :nodoc:
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ public struct AnyDatabaseRegionConvertible: DatabaseRegionConvertible {
|
||||
|
||||
/// :nodoc:
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try _region(db)
|
||||
try _region(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ public struct AnyDatabaseRegionConvertible: DatabaseRegionConvertible {
|
||||
|
||||
extension DatabaseRegion {
|
||||
static func union(_ regions: DatabaseRegion...) -> DatabaseRegion {
|
||||
return regions.reduce(into: DatabaseRegion()) { union, region in
|
||||
regions.reduce(into: DatabaseRegion()) { union, region in
|
||||
union.formUnion(region)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ private class DatabaseRegionObserver: TransactionObserver {
|
||||
}
|
||||
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
|
||||
return region.isModified(byEventsOfKind: eventKind)
|
||||
region.isModified(byEventsOfKind: eventKind)
|
||||
}
|
||||
|
||||
func databaseDidChange(with event: DatabaseEvent) {
|
||||
|
||||
@@ -15,7 +15,7 @@ struct DatabaseSchemaCache {
|
||||
}
|
||||
|
||||
func primaryKey(_ table: String) -> PrimaryKeyInfo? {
|
||||
return primaryKeys[table]
|
||||
primaryKeys[table]
|
||||
}
|
||||
|
||||
mutating func set(primaryKey: PrimaryKeyInfo, forTable table: String) {
|
||||
@@ -23,7 +23,7 @@ struct DatabaseSchemaCache {
|
||||
}
|
||||
|
||||
func columns(in table: String) -> [ColumnInfo]? {
|
||||
return columns[table]
|
||||
columns[table]
|
||||
}
|
||||
|
||||
mutating func set(columns: [ColumnInfo], forTable table: String) {
|
||||
@@ -31,7 +31,7 @@ struct DatabaseSchemaCache {
|
||||
}
|
||||
|
||||
func indexes(on table: String) -> [IndexInfo]? {
|
||||
return indexes[table]
|
||||
indexes[table]
|
||||
}
|
||||
|
||||
mutating func set(indexes: [IndexInfo], forTable table: String) {
|
||||
@@ -39,7 +39,7 @@ struct DatabaseSchemaCache {
|
||||
}
|
||||
|
||||
func foreignKeys(on table: String) -> [ForeignKeyInfo]? {
|
||||
return foreignKeys[table]
|
||||
foreignKeys[table]
|
||||
}
|
||||
|
||||
mutating func set(foreignKeys: [ForeignKeyInfo], forTable table: String) {
|
||||
|
||||
@@ -11,7 +11,7 @@ public class DatabaseSnapshot: DatabaseReader {
|
||||
|
||||
/// The database configuration
|
||||
public var configuration: Configuration {
|
||||
return serializedDatabase.configuration
|
||||
serializedDatabase.configuration
|
||||
}
|
||||
|
||||
init(path: String, configuration: Configuration = Configuration(), defaultLabel: String, purpose: String) throws {
|
||||
@@ -65,7 +65,7 @@ extension DatabaseSnapshot {
|
||||
/// - parameter block: A block that accesses the database.
|
||||
/// - throws: The error thrown by the block.
|
||||
public func read<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try serializedDatabase.sync(block)
|
||||
try serializedDatabase.sync(block)
|
||||
}
|
||||
|
||||
/// Asynchronously executes a read-only block in a protected dispatch queue.
|
||||
@@ -86,12 +86,12 @@ extension DatabaseSnapshot {
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) rethrows -> T {
|
||||
return try serializedDatabase.sync(block)
|
||||
try serializedDatabase.sync(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try serializedDatabase.reentrantSync(block)
|
||||
try serializedDatabase.reentrantSync(block)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
@@ -167,7 +167,7 @@ extension DatabaseSnapshot {
|
||||
/// An observer that does nothing, support for
|
||||
/// `DatabaseSnapshot.add(observation:onError:onChange:)`.
|
||||
private class SnapshotValueObserver: TransactionObserver {
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { return false }
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { false }
|
||||
func databaseDidChange(with event: DatabaseEvent) { }
|
||||
func databaseDidCommit(_ db: Database) { }
|
||||
func databaseDidRollback(_ db: Database) { }
|
||||
|
||||
@@ -209,12 +209,12 @@ extension DatabaseValue {
|
||||
extension DatabaseValue {
|
||||
/// Returns self
|
||||
public var databaseValue: DatabaseValue {
|
||||
return self
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the database value
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> DatabaseValue? {
|
||||
return dbValue
|
||||
dbValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ extension DatabaseValue {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ extension DatabaseValue {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ struct ValueConversionContext: KeyPathRefining {
|
||||
private var column: Column?
|
||||
|
||||
func atColumn(_ columnIndex: Int) -> ValueConversionContext {
|
||||
return with(\.column, .columnIndex(columnIndex))
|
||||
with(\.column, .columnIndex(columnIndex))
|
||||
}
|
||||
|
||||
func atColumn(_ columnName: String) -> ValueConversionContext {
|
||||
return with(\.column, .columnName(columnName))
|
||||
with(\.column, .columnName(columnName))
|
||||
}
|
||||
|
||||
var columnIndex: Int? {
|
||||
@@ -224,7 +224,7 @@ extension DatabaseValueConvertible {
|
||||
|
||||
@usableFromInline
|
||||
static func decode(from row: Row, atUncheckedIndex index: Int) -> Self {
|
||||
return decode(
|
||||
decode(
|
||||
from: row.impl.databaseValue(atUncheckedIndex: index),
|
||||
conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
@@ -258,7 +258,7 @@ extension DatabaseValueConvertible {
|
||||
|
||||
@usableFromInline
|
||||
static func decodeIfPresent(from row: Row, atUncheckedIndex index: Int) -> Self? {
|
||||
return decodeIfPresent(
|
||||
decodeIfPresent(
|
||||
from: row.impl.databaseValue(atUncheckedIndex: index),
|
||||
conversionContext: ValueConversionContext(row).atColumn(index))
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ extension DatabaseValueConvertible {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return databaseValue
|
||||
databaseValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
@@ -416,7 +416,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
@@ -431,7 +431,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,7 +620,7 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped:
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor<RowDecoder._Wrapped> {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
@@ -632,6 +632,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped:
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,7 @@ extension DatabaseWriter {
|
||||
/// - throws: The error thrown by the updates, or by the
|
||||
/// wrapping transaction.
|
||||
public func write<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
return try writeWithoutTransaction { db in
|
||||
try writeWithoutTransaction { db in
|
||||
var result: T?
|
||||
try db.inTransaction {
|
||||
result = try updates(db)
|
||||
@@ -568,7 +568,7 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
|
||||
/// :nodoc:
|
||||
public var configuration: Configuration {
|
||||
return base.configuration
|
||||
base.configuration
|
||||
}
|
||||
|
||||
// MARK: - Interrupting Database Operations
|
||||
@@ -582,7 +582,7 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
|
||||
/// :nodoc:
|
||||
public func read<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.read(block)
|
||||
try base.read(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -592,17 +592,17 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeRead(block)
|
||||
try base.unsafeRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantRead<T>(_ block: (Database) throws -> T) throws -> T {
|
||||
return try base.unsafeReentrantRead(block)
|
||||
try base.unsafeReentrantRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func concurrentRead<T>(_ block: @escaping (Database) throws -> T) -> DatabaseFuture<T> {
|
||||
return base.concurrentRead(block)
|
||||
base.concurrentRead(block)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -614,17 +614,17 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
|
||||
/// :nodoc:
|
||||
public func write<T>(_ updates: (Database) throws -> T) throws -> T {
|
||||
return try base.write(updates)
|
||||
try base.write(updates)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func writeWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try base.writeWithoutTransaction(updates)
|
||||
try base.writeWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func barrierWriteWithoutTransaction<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try base.barrierWriteWithoutTransaction(updates)
|
||||
try base.barrierWriteWithoutTransaction(updates)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -642,7 +642,7 @@ public final class AnyDatabaseWriter: DatabaseWriter {
|
||||
|
||||
/// :nodoc:
|
||||
public func unsafeReentrantWrite<T>(_ updates: (Database) throws -> T) rethrows -> T {
|
||||
return try base.unsafeReentrantWrite(updates)
|
||||
try base.unsafeReentrantWrite(updates)
|
||||
}
|
||||
|
||||
// MARK: - Functions
|
||||
|
||||
@@ -75,7 +75,7 @@ extension FetchRequest {
|
||||
|
||||
/// Returns an adapted request.
|
||||
public func adapted(_ adapter: @escaping (Database) throws -> RowAdapter) -> AdaptedFetchRequest<Self> {
|
||||
return AdaptedFetchRequest(self, adapter)
|
||||
AdaptedFetchRequest(self, adapter)
|
||||
}
|
||||
|
||||
/// Returns the number of rows fetched by the request.
|
||||
@@ -131,12 +131,12 @@ public struct AdaptedFetchRequest<Base: FetchRequest>: FetchRequest {
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try base.fetchCount(db)
|
||||
try base.fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try base.databaseRegion(db)
|
||||
try base.databaseRegion(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,16 +162,16 @@ public struct AnyFetchRequest<T>: FetchRequest {
|
||||
|
||||
/// :nodoc:
|
||||
public func makePreparedRequest(_ db: Database, forSingleResult singleResult: Bool) throws -> PreparedRequest {
|
||||
return try _preparedRequest(db, singleResult)
|
||||
try _preparedRequest(db, singleResult)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try _fetchCount(db)
|
||||
try _fetchCount(db)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func databaseRegion(_ db: Database) throws -> DatabaseRegion {
|
||||
return try _databaseRegion(db)
|
||||
try _databaseRegion(db)
|
||||
}
|
||||
}
|
||||
+49
-73
@@ -78,15 +78,13 @@ public final class Row: Equatable, Hashable, RandomAccessCollection,
|
||||
/// the iteration of a query: make sure to make a copy of it whenever you
|
||||
/// want to keep a specific one: `row.copy()`.
|
||||
public func copy() -> Row {
|
||||
return impl.copiedRow(self)
|
||||
impl.copiedRow(self)
|
||||
}
|
||||
|
||||
// MARK: - Not Public
|
||||
|
||||
/// Returns true if and only if the row was fetched from a database.
|
||||
var isFetched: Bool {
|
||||
return impl.isFetched
|
||||
}
|
||||
var isFetched: Bool { impl.isFetched }
|
||||
|
||||
/// Creates a row that maps an SQLite statement. Further calls to
|
||||
/// sqlite3_step() modify the row.
|
||||
@@ -142,19 +140,19 @@ extension Row {
|
||||
/// Columns appear in the same order as they occur as the `.0` member
|
||||
/// of column-value pairs in `self`.
|
||||
public var columnNames: LazyMapCollection<Row, String> {
|
||||
return lazy.map { $0.0 }
|
||||
lazy.map { $0.0 }
|
||||
}
|
||||
|
||||
/// Returns true if and only if the row has that column.
|
||||
///
|
||||
/// This method is case-insensitive.
|
||||
public func hasColumn(_ columnName: String) -> Bool {
|
||||
return index(ofColumn: columnName) != nil
|
||||
index(ofColumn: columnName) != nil
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
return impl.index(ofColumn: name)
|
||||
impl.index(ofColumn: name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,7 +500,7 @@ extension Row {
|
||||
/// The returned data does not owns its bytes: it must not be used longer
|
||||
/// than the row's lifetime.
|
||||
public func dataNoCopy<Column: ColumnExpression>(_ column: Column) -> Data? {
|
||||
return dataNoCopy(named: column.name)
|
||||
dataNoCopy(named: column.name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,7 +513,7 @@ extension Row {
|
||||
/// Values appear in the same order as they occur as the `.1` member
|
||||
/// of column-value pairs in `self`.
|
||||
public var databaseValues: LazyMapCollection<Row, DatabaseValue> {
|
||||
return lazy.map { $0.1 }
|
||||
lazy.map { $0.1 }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,7 +699,7 @@ extension Row {
|
||||
/// row.scopes["bar"] // [bar:2]
|
||||
/// row.scopes["baz"] // nil
|
||||
public var scopes: ScopesView {
|
||||
return impl.scopes(prefetchedRows: prefetchedRows)
|
||||
impl.scopes(prefetchedRows: prefetchedRows)
|
||||
}
|
||||
|
||||
/// Returns a view on the scopes tree defined by row adapters.
|
||||
@@ -724,7 +722,7 @@ extension Row {
|
||||
/// row.scopesTree["bar"] // [bar:2]
|
||||
/// row.scopesTree["baz"] // [baz:3]
|
||||
public var scopesTree: ScopesTreeView {
|
||||
return ScopesTreeView(scopes: scopes)
|
||||
ScopesTreeView(scopes: scopes)
|
||||
}
|
||||
|
||||
/// Returns a copy of the row, without any scopes.
|
||||
@@ -755,7 +753,7 @@ extension Row {
|
||||
/// This property can turn out useful when you debug the consumption of
|
||||
/// adapted rows, such as rows fetched from joined requests.
|
||||
public var unadapted: Row {
|
||||
return impl.unadaptedRow(self)
|
||||
impl.unadaptedRow(self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1093,7 +1091,7 @@ extension FetchRequest where RowDecoder == Row {
|
||||
/// - returns: A cursor over fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RowCursor {
|
||||
return try Row.fetchCursor(db, self)
|
||||
try Row.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched rows.
|
||||
@@ -1105,7 +1103,7 @@ extension FetchRequest where RowDecoder == Row {
|
||||
/// - returns: An array of fetched rows.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [Row] {
|
||||
return try Row.fetchAll(db, self)
|
||||
try Row.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched row.
|
||||
@@ -1117,7 +1115,7 @@ extension FetchRequest where RowDecoder == Row {
|
||||
/// - returns: An optional row.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> Row? {
|
||||
return try Row.fetchOne(db, self)
|
||||
try Row.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1142,16 +1140,12 @@ extension Row {
|
||||
|
||||
/// The index of the first (ColumnName, DatabaseValue) pair.
|
||||
/// :nodoc:
|
||||
public var startIndex: RowIndex {
|
||||
return Index(0)
|
||||
}
|
||||
public var startIndex: RowIndex { RowIndex(0) }
|
||||
|
||||
/// The "past-the-end" index, successor of the index of the last
|
||||
/// (ColumnName, DatabaseValue) pair.
|
||||
/// :nodoc:
|
||||
public var endIndex: RowIndex {
|
||||
return Index(count)
|
||||
}
|
||||
public var endIndex: RowIndex { RowIndex(count) }
|
||||
|
||||
/// Accesses the (ColumnName, DatabaseValue) pair at given index.
|
||||
public subscript(position: RowIndex) -> (String, DatabaseValue) {
|
||||
@@ -1225,14 +1219,14 @@ extension Row {
|
||||
extension Row {
|
||||
/// :nodoc:
|
||||
public var description: String {
|
||||
return "["
|
||||
"["
|
||||
+ map { (column, dbValue) in "\(column):\(dbValue)" }.joined(separator: " ")
|
||||
+ "]"
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public var debugDescription: String {
|
||||
return debugDescription(level: 0)
|
||||
debugDescription(level: 0)
|
||||
}
|
||||
|
||||
private func debugDescription(level: Int) -> String {
|
||||
@@ -1284,12 +1278,12 @@ public struct RowIndex: Comparable, Strideable {
|
||||
extension RowIndex {
|
||||
/// :nodoc:
|
||||
public static func == (lhs: RowIndex, rhs: RowIndex) -> Bool {
|
||||
return lhs.index == rhs.index
|
||||
lhs.index == rhs.index
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public static func < (lhs: RowIndex, rhs: RowIndex) -> Bool {
|
||||
return lhs.index < rhs.index
|
||||
lhs.index < rhs.index
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,12 +1291,12 @@ extension RowIndex {
|
||||
extension RowIndex {
|
||||
/// :nodoc:
|
||||
public func distance(to other: RowIndex) -> Int {
|
||||
return other.index - index
|
||||
other.index - index
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func advanced(by n: Int) -> RowIndex {
|
||||
return RowIndex(index + n)
|
||||
RowIndex(index + n)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1339,7 +1333,7 @@ extension Row {
|
||||
|
||||
/// The scopes defined on this row.
|
||||
public var names: Dictionary<String, LayoutedRowAdapter>.Keys {
|
||||
return scopes.keys
|
||||
scopes.keys
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -1354,17 +1348,17 @@ extension Row {
|
||||
|
||||
/// :nodoc:
|
||||
public var startIndex: Index {
|
||||
return scopes.startIndex
|
||||
scopes.startIndex
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public var endIndex: Index {
|
||||
return scopes.endIndex
|
||||
scopes.endIndex
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func index(after i: Index) -> Index {
|
||||
return scopes.index(after: i)
|
||||
scopes.index(after: i)
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -1500,7 +1494,7 @@ extension Row {
|
||||
|
||||
/// True if there is no prefetched associated rows.
|
||||
public var isEmpty: Bool {
|
||||
return prefetches.isEmpty
|
||||
prefetches.isEmpty
|
||||
}
|
||||
|
||||
/// The keys for available prefetched rows
|
||||
@@ -1666,20 +1660,16 @@ private struct ArrayRowImpl: RowImpl {
|
||||
self.columns = columns
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return columns.count
|
||||
}
|
||||
var count: Int { columns.count }
|
||||
|
||||
var isFetched: Bool {
|
||||
return false
|
||||
}
|
||||
var isFetched: Bool { false }
|
||||
|
||||
func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue {
|
||||
return columns[index].1
|
||||
columns[index].1
|
||||
}
|
||||
|
||||
func columnName(atUncheckedIndex index: Int) -> String {
|
||||
return columns[index].0
|
||||
columns[index].0
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
@@ -1688,7 +1678,7 @@ private struct ArrayRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func copiedRow(_ row: Row) -> Row {
|
||||
return row
|
||||
row
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1708,20 +1698,16 @@ private struct StatementCopyRowImpl: RowImpl {
|
||||
self.columnNames = columnNames
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return columnNames.count
|
||||
}
|
||||
var count: Int { columnNames.count }
|
||||
|
||||
var isFetched: Bool {
|
||||
return true
|
||||
}
|
||||
var isFetched: Bool { true }
|
||||
|
||||
func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue {
|
||||
return dbValues[index]
|
||||
dbValues[index]
|
||||
}
|
||||
|
||||
func columnName(atUncheckedIndex index: Int) -> String {
|
||||
return columnNames[index]
|
||||
columnNames[index]
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
@@ -1730,7 +1716,7 @@ private struct StatementCopyRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func copiedRow(_ row: Row) -> Row {
|
||||
return row
|
||||
row
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1755,12 +1741,10 @@ private struct StatementRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return Int(sqlite3_column_count(sqliteStatement))
|
||||
Int(sqlite3_column_count(sqliteStatement))
|
||||
}
|
||||
|
||||
var isFetched: Bool {
|
||||
return true
|
||||
}
|
||||
var isFetched: Bool { true }
|
||||
|
||||
func hasNull(atUncheckedIndex index: Int) -> Bool {
|
||||
// Avoid extracting values, because this modifies the SQLite statement.
|
||||
@@ -1779,7 +1763,7 @@ private struct StatementRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue {
|
||||
return DatabaseValue(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
DatabaseValue(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
}
|
||||
|
||||
func fastDecode<Value: DatabaseValueConvertible & StatementColumnConvertible>(
|
||||
@@ -1797,7 +1781,7 @@ private struct StatementRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func columnName(atUncheckedIndex index: Int) -> String {
|
||||
return statement.columnNames[index]
|
||||
statement.columnNames[index]
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
@@ -1808,22 +1792,22 @@ private struct StatementRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func copiedRow(_ row: Row) -> Row {
|
||||
return Row(copiedFromSQLiteStatement: sqliteStatement, statement: statement)
|
||||
Row(copiedFromSQLiteStatement: sqliteStatement, statement: statement)
|
||||
}
|
||||
}
|
||||
|
||||
// This one is not optimized at all, since it is only used in fatal conversion errors, so far
|
||||
private struct SQLiteStatementRowImpl: RowImpl {
|
||||
let sqliteStatement: SQLiteStatement
|
||||
var count: Int { return Int(sqlite3_column_count(sqliteStatement)) }
|
||||
var isFetched: Bool { return true }
|
||||
var count: Int { Int(sqlite3_column_count(sqliteStatement)) }
|
||||
var isFetched: Bool { true }
|
||||
|
||||
func columnName(atUncheckedIndex index: Int) -> String {
|
||||
return String(cString: sqlite3_column_name(sqliteStatement, Int32(index)))
|
||||
String(cString: sqlite3_column_name(sqliteStatement, Int32(index)))
|
||||
}
|
||||
|
||||
func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue {
|
||||
return DatabaseValue(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
DatabaseValue(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
}
|
||||
|
||||
func dataNoCopy(atUncheckedIndex index: Int) -> Data? {
|
||||
@@ -1848,13 +1832,9 @@ private struct SQLiteStatementRowImpl: RowImpl {
|
||||
|
||||
/// See Row.init()
|
||||
private struct EmptyRowImpl: RowImpl {
|
||||
var count: Int {
|
||||
return 0
|
||||
}
|
||||
var count: Int { 0 }
|
||||
|
||||
var isFetched: Bool {
|
||||
return false
|
||||
}
|
||||
var isFetched: Bool { false }
|
||||
|
||||
func databaseValue(atUncheckedIndex index: Int) -> DatabaseValue {
|
||||
// Programmer error
|
||||
@@ -1866,11 +1846,7 @@ private struct EmptyRowImpl: RowImpl {
|
||||
fatalError("row index out of range")
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
return nil
|
||||
}
|
||||
func index(ofColumn name: String) -> Int? { nil }
|
||||
|
||||
func copiedRow(_ row: Row) -> Row {
|
||||
return row
|
||||
}
|
||||
func copiedRow(_ row: Row) -> Row { row }
|
||||
}
|
||||
+18
-26
@@ -89,11 +89,11 @@ public struct LayoutedColumnMapping {
|
||||
}
|
||||
|
||||
func baseColumnIndex(atMappingIndex index: Int) -> Int {
|
||||
return layoutColumns[index].0
|
||||
layoutColumns[index].0
|
||||
}
|
||||
|
||||
func columnName(atMappingIndex index: Int) -> String {
|
||||
return layoutColumns[index].1
|
||||
layoutColumns[index].1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,16 +104,12 @@ extension LayoutedColumnMapping: LayoutedRowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// Returns self.
|
||||
public var mapping: LayoutedColumnMapping {
|
||||
return self
|
||||
}
|
||||
public var mapping: LayoutedColumnMapping { self }
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
///
|
||||
/// Returns the empty dictionary.
|
||||
public var scopes: [String: LayoutedRowAdapter] {
|
||||
return [:]
|
||||
}
|
||||
public var scopes: [String: LayoutedRowAdapter] { [:] }
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
@@ -175,13 +171,13 @@ extension SelectStatement: RowLayout {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var layoutColumns: [(Int, String)] {
|
||||
return Array(columnNames.enumerated())
|
||||
Array(columnNames.enumerated())
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func layoutIndex(ofColumn name: String) -> Int? {
|
||||
return index(ofColumn: name)
|
||||
index(ofColumn: name)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +243,7 @@ extension RowAdapter {
|
||||
|
||||
extension RowAdapter {
|
||||
func baseColumnIndex(atIndex index: Int, layout: RowLayout) throws -> Int {
|
||||
return try layoutedAdapter(from: layout).mapping.baseColumnIndex(atMappingIndex: index)
|
||||
try layoutedAdapter(from: layout).mapping.baseColumnIndex(atMappingIndex: index)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,7 +255,7 @@ public struct EmptyRowAdapter: RowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return LayoutedColumnMapping(layoutColumns: [])
|
||||
LayoutedColumnMapping(layoutColumns: [])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,7 +321,7 @@ public struct SuffixRowAdapter: RowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return LayoutedColumnMapping(layoutColumns: layout.layoutColumns.suffix(from: index))
|
||||
LayoutedColumnMapping(layoutColumns: layout.layoutColumns.suffix(from: index))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,7 +351,7 @@ public struct RangeRowAdapter: RowAdapter {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return LayoutedColumnMapping(layoutColumns: layout.layoutColumns[range])
|
||||
LayoutedColumnMapping(layoutColumns: layout.layoutColumns[range])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,7 +450,7 @@ struct ChainedAdapter: RowAdapter {
|
||||
let second: RowAdapter
|
||||
|
||||
func layoutedAdapter(from layout: RowLayout) throws -> LayoutedRowAdapter {
|
||||
return try second.layoutedAdapter(from: first.layoutedAdapter(from: layout).mapping)
|
||||
try second.layoutedAdapter(from: first.layoutedAdapter(from: layout).mapping)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,16 +480,12 @@ struct AdaptedRowImpl: RowImpl {
|
||||
self.mapping = adapter.mapping
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return mapping.layoutColumns.count
|
||||
}
|
||||
var count: Int { mapping.layoutColumns.count }
|
||||
|
||||
var isFetched: Bool {
|
||||
return base.isFetched
|
||||
}
|
||||
var isFetched: Bool { base.isFetched }
|
||||
|
||||
func scopes(prefetchedRows: Row.PrefetchedRowsView) -> Row.ScopesView {
|
||||
return Row.ScopesView(row: base, scopes: adapter.scopes, prefetchedRows: prefetchedRows)
|
||||
Row.ScopesView(row: base, scopes: adapter.scopes, prefetchedRows: prefetchedRows)
|
||||
}
|
||||
|
||||
func hasNull(atUncheckedIndex index: Int) -> Bool {
|
||||
@@ -528,15 +520,15 @@ struct AdaptedRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func columnName(atUncheckedIndex index: Int) -> String {
|
||||
return mapping.columnName(atMappingIndex: index)
|
||||
mapping.columnName(atMappingIndex: index)
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? {
|
||||
return mapping.layoutIndex(ofColumn: name)
|
||||
mapping.layoutIndex(ofColumn: name)
|
||||
}
|
||||
|
||||
func copiedRow(_ row: Row) -> Row {
|
||||
return Row(base: base.copy(), adapter: adapter)
|
||||
Row(base: base.copy(), adapter: adapter)
|
||||
}
|
||||
|
||||
func unscopedRow(_ row: Row) -> Row {
|
||||
@@ -545,6 +537,6 @@ struct AdaptedRowImpl: RowImpl {
|
||||
}
|
||||
|
||||
func unadaptedRow(_ row: Row) -> Row {
|
||||
return base.unadapted
|
||||
base.unadapted
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -21,7 +21,7 @@ public struct SQLLiteral {
|
||||
|
||||
// TODO: remove and use default case argument when compiler >= 5.1
|
||||
static func sql(_ sql: String) -> Element {
|
||||
return .sql(sql, StatementArguments())
|
||||
.sql(sql, StatementArguments())
|
||||
}
|
||||
|
||||
fileprivate func sql(_ context: inout SQLGenerationContext) -> String {
|
||||
@@ -103,11 +103,11 @@ public struct SQLLiteral {
|
||||
}
|
||||
|
||||
func sql(_ context: inout SQLGenerationContext) -> String {
|
||||
return elements.map { $0.sql(&context) }.joined()
|
||||
elements.map { $0.sql(&context) }.joined()
|
||||
}
|
||||
|
||||
fileprivate func qualified(with alias: TableAlias) -> SQLLiteral {
|
||||
return SQLLiteral(elements: elements.map { $0.qualified(with: alias) })
|
||||
SQLLiteral(elements: elements.map { $0.qualified(with: alias) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,15 +159,15 @@ extension SQLLiteral {
|
||||
/// SQLLiteral(sql: "? + ?", arguments: [1, 2]).sqlExpression
|
||||
/// SQLLiteral(sql: ":one + :two", arguments: ["one": 1, "two": 2]).sqlExpression
|
||||
public var sqlExpression: SQLExpression {
|
||||
return _SQLExpressionLiteral(sqlLiteral: self)
|
||||
_SQLExpressionLiteral(sqlLiteral: self)
|
||||
}
|
||||
|
||||
var sqlSelectable: SQLSelectable {
|
||||
return _SQLSelectionLiteral(sqlLiteral: self)
|
||||
_SQLSelectionLiteral(sqlLiteral: self)
|
||||
}
|
||||
|
||||
var sqlOrderingTerm: SQLOrderingTerm {
|
||||
return _SQLOrderingLiteral(sqlLiteral: self)
|
||||
_SQLOrderingLiteral(sqlLiteral: self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ private struct _SQLExpressionLiteral: SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return sqlLiteral.qualified(with: alias).sqlExpression
|
||||
sqlLiteral.qualified(with: alias).sqlExpression
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ private struct _SQLSelectionLiteral: SQLSelectable {
|
||||
}
|
||||
|
||||
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlLiteral.sql(&context)
|
||||
sqlLiteral.sql(&context)
|
||||
}
|
||||
|
||||
func countedSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
@@ -308,7 +308,7 @@ private struct _SQLSelectionLiteral: SQLSelectable {
|
||||
}
|
||||
|
||||
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
|
||||
return sqlLiteral.qualified(with: alias).sqlSelectable
|
||||
sqlLiteral.qualified(with: alias).sqlSelectable
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,10 +330,10 @@ private struct _SQLOrderingLiteral: SQLOrderingTerm {
|
||||
}
|
||||
|
||||
func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlLiteral.sql(&context)
|
||||
sqlLiteral.sql(&context)
|
||||
}
|
||||
|
||||
func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
|
||||
return sqlLiteral.qualified(with: alias).sqlOrderingTerm
|
||||
sqlLiteral.qualified(with: alias).sqlOrderingTerm
|
||||
}
|
||||
}
|
||||
@@ -19,14 +19,14 @@ public struct SQLRequest<T>: FetchRequest {
|
||||
/// let id = 42
|
||||
/// let request: SQLRequest<Player> = "SELECT * FROM player WHERE id = \(id)"
|
||||
/// request.sql // "SELECT * FROM player WHERE id = ?"
|
||||
public var sql: String { return sqlLiteral.sql }
|
||||
public var sql: String { sqlLiteral.sql }
|
||||
|
||||
/// The request argument
|
||||
///
|
||||
/// let id = 42
|
||||
/// let request: SQLRequest<Player> = "SELECT * FROM player WHERE id = \(id)"
|
||||
/// request.arguments // [42]
|
||||
public var arguments: StatementArguments { return sqlLiteral.arguments }
|
||||
public var arguments: StatementArguments { sqlLiteral.arguments }
|
||||
|
||||
/// The request adapter
|
||||
public var adapter: RowAdapter?
|
||||
|
||||
@@ -53,10 +53,10 @@ final class SchedulingWatchdog {
|
||||
}
|
||||
|
||||
static var current: SchedulingWatchdog? {
|
||||
return DispatchQueue.getSpecific(key: watchDogKey)
|
||||
DispatchQueue.getSpecific(key: watchDogKey)
|
||||
}
|
||||
|
||||
func allows(_ db: Database) -> Bool {
|
||||
return allowedDatabases.contains { $0 === db }
|
||||
allowedDatabases.contains { $0 === db }
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,7 @@ final class SerializedDatabase {
|
||||
private let db: Database
|
||||
|
||||
/// The database configuration
|
||||
var configuration: Configuration {
|
||||
return db.configuration
|
||||
}
|
||||
var configuration: Configuration { db.configuration }
|
||||
|
||||
/// The path to the database file
|
||||
var path: String
|
||||
@@ -188,7 +186,7 @@ final class SerializedDatabase {
|
||||
|
||||
/// Returns true if any only if the current dispatch queue is valid.
|
||||
var onValidQueue: Bool {
|
||||
return SchedulingWatchdog.current?.allows(db) ?? false
|
||||
SchedulingWatchdog.current?.allows(db) ?? false
|
||||
}
|
||||
|
||||
/// Executes the block in the current queue.
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Statement {
|
||||
}
|
||||
|
||||
var isReadonly: Bool {
|
||||
return sqlite3_stmt_readonly(sqliteStatement) != 0
|
||||
sqlite3_stmt_readonly(sqliteStatement) != 0
|
||||
}
|
||||
|
||||
unowned let database: Database
|
||||
@@ -124,7 +124,7 @@ public class Statement {
|
||||
|
||||
/// The statement arguments.
|
||||
public var arguments: StatementArguments {
|
||||
get { return _arguments }
|
||||
get { _arguments }
|
||||
set {
|
||||
// Force arguments validity: it is a programmer error to provide
|
||||
// arguments that do not match the statement.
|
||||
@@ -367,7 +367,7 @@ public final class SelectStatement: Statement {
|
||||
|
||||
/// The number of columns in the resulting rows.
|
||||
public var columnCount: Int {
|
||||
return Int(sqlite3_column_count(self.sqliteStatement))
|
||||
Int(sqlite3_column_count(self.sqliteStatement))
|
||||
}
|
||||
|
||||
/// The column names, ordered from left to right.
|
||||
@@ -386,14 +386,14 @@ public final class SelectStatement: Statement {
|
||||
/// Returns the index of the leftmost column named `name`, in a
|
||||
/// case-insensitive way.
|
||||
public func index(ofColumn name: String) -> Int? {
|
||||
return columnIndexes[name.lowercased()]
|
||||
columnIndexes[name.lowercased()]
|
||||
}
|
||||
|
||||
/// Creates a cursor over the statement which does not produce any
|
||||
/// value. Each call to the next() cursor method calls the sqlite3_step()
|
||||
/// C function.
|
||||
func makeCursor(arguments: StatementArguments? = nil) throws -> StatementCursor {
|
||||
return try StatementCursor(statement: self, arguments: arguments)
|
||||
try StatementCursor(statement: self, arguments: arguments)
|
||||
}
|
||||
|
||||
/// Utility function for cursors
|
||||
@@ -648,7 +648,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable,
|
||||
private(set) var namedValues: [String: DatabaseValue] = [:]
|
||||
|
||||
public var isEmpty: Bool {
|
||||
return values.isEmpty && namedValues.isEmpty
|
||||
values.isEmpty && namedValues.isEmpty
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> FastDatabaseValueCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched values.
|
||||
@@ -420,7 +420,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched value.
|
||||
@@ -435,7 +435,7 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol
|
||||
/// - returns: An optional value.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -628,7 +628,7 @@ extension FetchRequest
|
||||
/// - returns: A cursor over fetched values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> FastNullableDatabaseValueCursor<RowDecoder._Wrapped> {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
try Optional<RowDecoder._Wrapped>.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched optional values.
|
||||
@@ -640,6 +640,6 @@ extension FetchRequest
|
||||
/// - returns: An array of values.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] {
|
||||
return try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
try Optional<RowDecoder._Wrapped>.fetchAll(db, self)
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ extension CGFloat: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Double(self).databaseValue
|
||||
Double(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a CGFloat initialized from *dbValue*, if possible.
|
||||
|
||||
@@ -21,7 +21,7 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(storage: .blob(self))
|
||||
DatabaseValue(storage: .blob(self))
|
||||
}
|
||||
|
||||
/// Returns a Data initialized from *dbValue*, if it contains
|
||||
|
||||
@@ -17,12 +17,12 @@ extension DatabaseValueConvertible where Self: ReferenceConvertible, Self.Refere
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return (self as! ReferenceType).databaseValue
|
||||
(self as! ReferenceType).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
||||
return ReferenceType.fromDatabaseValue(dbValue).flatMap { cast($0) }
|
||||
ReferenceType.fromDatabaseValue(dbValue).flatMap { cast($0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ extension NSDate: DatabaseValueConvertible {
|
||||
/// Returns a database value that contains the date encoded as
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return (self as Date).databaseValue
|
||||
(self as Date).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a date initialized from dbValue, if possible.
|
||||
@@ -42,7 +42,7 @@ extension Date: DatabaseValueConvertible {
|
||||
/// Returns a database value that contains the date encoded as
|
||||
/// "yyyy-MM-dd HH:mm:ss.SSS", in the UTC time zone.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return storageDateFormatter.string(from: self).databaseValue
|
||||
storageDateFormatter.string(from: self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a date initialized from dbValue, if possible.
|
||||
|
||||
@@ -6,7 +6,7 @@ extension NSData: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return (self as Data).databaseValue
|
||||
(self as Data).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an NSData initialized from *dbValue*, if it contains
|
||||
|
||||
@@ -4,12 +4,8 @@ import Foundation
|
||||
extension NSNull: DatabaseValueConvertible {
|
||||
|
||||
/// Returns DatabaseValue.null.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return .null
|
||||
}
|
||||
public var databaseValue: DatabaseValue { .null }
|
||||
|
||||
/// Returns nil.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
||||
return nil
|
||||
}
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? { nil }
|
||||
}
|
||||
@@ -6,7 +6,7 @@ extension NSString: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return (self as String).databaseValue
|
||||
(self as String).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an NSString initialized from *dbValue*, if possible.
|
||||
|
||||
@@ -15,7 +15,7 @@ class SQLiteDateParser {
|
||||
}
|
||||
|
||||
func components(from dateString: String) -> DatabaseDateComponents? {
|
||||
return dateString.withCString { cString in
|
||||
dateString.withCString { cString in
|
||||
components(cString: cString, length: strlen(cString))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ extension NSURL: DatabaseValueConvertible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
/// (the URL's absoluteString).
|
||||
public var databaseValue: DatabaseValue {
|
||||
return absoluteString?.databaseValue ?? .null
|
||||
absoluteString?.databaseValue ?? .null
|
||||
}
|
||||
|
||||
/// Returns an NSURL initialized from *dbValue*, if possible.
|
||||
|
||||
@@ -36,7 +36,7 @@ extension NSUUID: DatabaseValueConvertible {
|
||||
/// UUID adopts DatabaseValueConvertible
|
||||
extension UUID: DatabaseValueConvertible {
|
||||
public var databaseValue: DatabaseValue {
|
||||
return withUnsafeBytes(of: uuid) {
|
||||
withUnsafeBytes(of: uuid) {
|
||||
Data(bytes: $0.baseAddress!, count: $0.count).databaseValue
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ private struct DatabaseValueDecodingContainer: SingleValueDecodingContainer {
|
||||
/// Decodes a null value.
|
||||
///
|
||||
/// - returns: Whether the encountered value was null.
|
||||
func decodeNil() -> Bool {
|
||||
return dbValue.isNull
|
||||
}
|
||||
func decodeNil() -> Bool { dbValue.isNull }
|
||||
|
||||
/// Decodes a single value of the given type.
|
||||
///
|
||||
@@ -161,7 +159,7 @@ private struct DatabaseValueDecoder: Decoder {
|
||||
|
||||
// Decoder
|
||||
let codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any] { return [:] }
|
||||
var userInfo: [CodingUserInfoKey: Any] { [:] }
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
|
||||
throw DecodingError.typeMismatch(
|
||||
@@ -176,13 +174,13 @@ private struct DatabaseValueDecoder: Decoder {
|
||||
}
|
||||
|
||||
func singleValueContainer() throws -> SingleValueDecodingContainer {
|
||||
return DatabaseValueDecodingContainer(dbValue: dbValue, codingPath: codingPath)
|
||||
DatabaseValueDecodingContainer(dbValue: dbValue, codingPath: codingPath)
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseValueConvertible where Self: Decodable {
|
||||
public static func fromDatabaseValue(_ databaseValue: DatabaseValue) -> Self? {
|
||||
return try? self.init(from: DatabaseValueDecoder(dbValue: databaseValue, codingPath: []))
|
||||
try? self.init(from: DatabaseValueDecoder(dbValue: databaseValue, codingPath: []))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
private struct DatabaseValueEncodingContainer: SingleValueEncodingContainer {
|
||||
let encode: (DatabaseValue) -> Void
|
||||
|
||||
var codingPath: [CodingKey] { return [] }
|
||||
var codingPath: [CodingKey] { [] }
|
||||
|
||||
/// Encodes a null value.
|
||||
///
|
||||
@@ -50,7 +50,7 @@ private struct DatabaseValueEncoder: Encoder {
|
||||
|
||||
/// The path of coding keys taken to get to this point in encoding.
|
||||
/// A `nil` value indicates an unkeyed container.
|
||||
var codingPath: [CodingKey] { return [] }
|
||||
var codingPath: [CodingKey] { [] }
|
||||
|
||||
/// Any contextual information set by the user for encoding.
|
||||
var userInfo: [CodingUserInfoKey: Any] = [:]
|
||||
@@ -88,7 +88,7 @@ private struct DatabaseValueEncoder: Encoder {
|
||||
/// - precondition: May not be called after a value has been encoded through
|
||||
/// a previous `self.singleValueContainer()` call.
|
||||
func singleValueContainer() -> SingleValueEncodingContainer {
|
||||
return DatabaseValueEncodingContainer(encode: encode)
|
||||
DatabaseValueEncodingContainer(encode: encode)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ extension DatabaseValueConvertible where Self: RawRepresentable, Self.RawValue:
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawValue.databaseValue
|
||||
rawValue.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Self? {
|
||||
return RawValue.fromDatabaseValue(dbValue).flatMap { self.init(rawValue: $0) }
|
||||
RawValue.fromDatabaseValue(dbValue).flatMap { self.init(rawValue: $0) }
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return (self ? 1 : 0).databaseValue
|
||||
(self ? 1 : 0).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a Bool initialized from *dbValue*, if possible.
|
||||
@@ -115,12 +115,12 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an Int initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Int? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { Int(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +144,12 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an Int8 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Int8? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { Int8(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int8(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,12 +173,12 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an Int16 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Int16? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { Int16(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int16(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,12 +202,12 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an Int32 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Int32? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { Int32(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { Int32(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(storage: .int64(self))
|
||||
DatabaseValue(storage: .int64(self))
|
||||
}
|
||||
|
||||
/// Returns an Int64 initialized from *dbValue*, if possible.
|
||||
@@ -264,12 +264,12 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an Int initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UInt? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { UInt(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,12 +293,12 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an UInt8 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UInt8? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { UInt8(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt8(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,12 +322,12 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an UInt16 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UInt16? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { UInt16(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt16(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,12 +351,12 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an UInt32 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UInt32? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { UInt32(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt32(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,12 +380,12 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Int64(self).databaseValue
|
||||
Int64(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns an UInt64 initialized from *dbValue*, if possible.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> UInt64? {
|
||||
return Int64.fromDatabaseValue(dbValue).flatMap { UInt64(exactly: $0) }
|
||||
Int64.fromDatabaseValue(dbValue).flatMap { UInt64(exactly: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +404,7 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(storage: .double(self))
|
||||
DatabaseValue(storage: .double(self))
|
||||
}
|
||||
|
||||
/// Returns a Double initialized from *dbValue*, if possible.
|
||||
@@ -435,7 +435,7 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return Double(self).databaseValue
|
||||
Double(self).databaseValue
|
||||
}
|
||||
|
||||
/// Returns a Float initialized from *dbValue*, if possible.
|
||||
@@ -466,7 +466,7 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(storage: .string(self))
|
||||
DatabaseValue(storage: .string(self))
|
||||
}
|
||||
|
||||
/// Returns a String initialized from *dbValue*, if possible.
|
||||
|
||||
@@ -54,7 +54,7 @@ extension Database {
|
||||
}
|
||||
|
||||
// Ignore individual changes and transaction rollbacks
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { return false }
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool { false }
|
||||
func databaseDidChange(with event: DatabaseEvent) { }
|
||||
func databaseDidRollback(_ db: Database) { }
|
||||
|
||||
@@ -794,10 +794,10 @@ final class TransactionObservation {
|
||||
|
||||
private weak var weakObserver: TransactionObserver?
|
||||
private var strongObserver: TransactionObserver?
|
||||
private var observer: TransactionObserver? { return strongObserver ?? weakObserver }
|
||||
private var observer: TransactionObserver? { strongObserver ?? weakObserver }
|
||||
|
||||
fileprivate var isObserving: Bool {
|
||||
return observer != nil
|
||||
observer != nil
|
||||
}
|
||||
|
||||
init(observer: TransactionObserver, extent: Database.TransactionObservationExtent) {
|
||||
@@ -814,7 +814,7 @@ final class TransactionObservation {
|
||||
}
|
||||
|
||||
func isWrapping(_ observer: TransactionObserver) -> Bool {
|
||||
return self.observer === observer
|
||||
self.observer === observer
|
||||
}
|
||||
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
|
||||
@@ -934,10 +934,10 @@ public struct DatabaseEvent {
|
||||
public let kind: Kind
|
||||
|
||||
/// The database name
|
||||
public var databaseName: String { return impl.databaseName }
|
||||
public var databaseName: String { impl.databaseName }
|
||||
|
||||
/// The table name
|
||||
public var tableName: String { return impl.tableName }
|
||||
public var tableName: String { impl.tableName }
|
||||
|
||||
/// The rowID of the changed row.
|
||||
public let rowID: Int64
|
||||
@@ -951,7 +951,7 @@ public struct DatabaseEvent {
|
||||
/// }
|
||||
/// }
|
||||
public func copy() -> DatabaseEvent {
|
||||
return impl.copy(self)
|
||||
impl.copy(self)
|
||||
}
|
||||
|
||||
fileprivate init(kind: Kind, rowID: Int64, impl: DatabaseEventImpl) {
|
||||
@@ -999,11 +999,11 @@ private struct MetalDatabaseEventImpl: DatabaseEventImpl {
|
||||
let databaseNameCString: UnsafePointer<Int8>?
|
||||
let tableNameCString: UnsafePointer<Int8>?
|
||||
|
||||
var databaseName: String { return String(cString: databaseNameCString!) }
|
||||
var tableName: String { return String(cString: tableNameCString!) }
|
||||
var databaseName: String { String(cString: databaseNameCString!) }
|
||||
var tableName: String { String(cString: tableNameCString!) }
|
||||
|
||||
func copy(_ event: DatabaseEvent) -> DatabaseEvent {
|
||||
return DatabaseEvent(
|
||||
DatabaseEvent(
|
||||
kind: event.kind,
|
||||
rowID: event.rowID,
|
||||
impl: CopiedDatabaseEventImpl(
|
||||
@@ -1016,9 +1016,7 @@ private struct MetalDatabaseEventImpl: DatabaseEventImpl {
|
||||
private struct CopiedDatabaseEventImpl: DatabaseEventImpl {
|
||||
let databaseName: String
|
||||
let tableName: String
|
||||
func copy(_ event: DatabaseEvent) -> DatabaseEvent {
|
||||
return event
|
||||
}
|
||||
func copy(_ event: DatabaseEvent) -> DatabaseEvent { event }
|
||||
}
|
||||
|
||||
#if SQLITE_ENABLE_PREUPDATE_HOOK
|
||||
@@ -1041,13 +1039,13 @@ public struct DatabasePreUpdateEvent {
|
||||
public let kind: Kind
|
||||
|
||||
/// The database name
|
||||
public var databaseName: String { return impl.databaseName }
|
||||
public var databaseName: String { impl.databaseName }
|
||||
|
||||
/// The table name
|
||||
public var tableName: String { return impl.tableName }
|
||||
public var tableName: String { impl.tableName }
|
||||
|
||||
/// The number of columns in the row that is being inserted, updated, or deleted.
|
||||
public var count: Int { return Int(impl.columnsCount) }
|
||||
public var count: Int { Int(impl.columnsCount) }
|
||||
|
||||
/// The triggering depth of the row update
|
||||
/// Returns:
|
||||
@@ -1056,7 +1054,7 @@ public struct DatabasePreUpdateEvent {
|
||||
/// 1 for inserts, updates, or deletes invoked by top-level triggers;
|
||||
/// 2 for changes resulting from triggers called by top-level triggers;
|
||||
/// ... and so forth
|
||||
public var depth: CInt { return impl.depth }
|
||||
public var depth: CInt { impl.depth }
|
||||
|
||||
/// The initial rowID of the row being changed for .Update and .Delete changes,
|
||||
/// and nil for .Insert changes.
|
||||
@@ -1119,7 +1117,7 @@ public struct DatabasePreUpdateEvent {
|
||||
/// }
|
||||
/// }
|
||||
public func copy() -> DatabasePreUpdateEvent {
|
||||
return impl.copy(self)
|
||||
impl.copy(self)
|
||||
}
|
||||
|
||||
fileprivate init(kind: Kind, initialRowID: Int64?, finalRowID: Int64?, impl: DatabasePreUpdateEventImpl) {
|
||||
@@ -1194,11 +1192,11 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
let databaseNameCString: UnsafePointer<Int8>?
|
||||
let tableNameCString: UnsafePointer<Int8>?
|
||||
|
||||
var databaseName: String { return String(cString: databaseNameCString!) }
|
||||
var tableName: String { return String(cString: tableNameCString!) }
|
||||
var databaseName: String { String(cString: databaseNameCString!) }
|
||||
var tableName: String { String(cString: tableNameCString!) }
|
||||
|
||||
var columnsCount: CInt { return sqlite3_preupdate_count(connection) }
|
||||
var depth: CInt { return sqlite3_preupdate_depth(connection) }
|
||||
var columnsCount: CInt { sqlite3_preupdate_count(connection) }
|
||||
var depth: CInt { sqlite3_preupdate_depth(connection) }
|
||||
var initialDatabaseValues: [DatabaseValue]? {
|
||||
guard kind == .update || kind == .delete else { return nil }
|
||||
return preupdate_getValues_old(connection)
|
||||
@@ -1232,7 +1230,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
}
|
||||
|
||||
func copy(_ event: DatabasePreUpdateEvent) -> DatabasePreUpdateEvent {
|
||||
return DatabasePreUpdateEvent(
|
||||
DatabasePreUpdateEvent(
|
||||
kind: event.kind,
|
||||
initialRowID: event.initialRowID,
|
||||
finalRowID: event.finalRowID,
|
||||
@@ -1278,7 +1276,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
}
|
||||
|
||||
private func preupdate_getValues_old(_ connection: SQLiteConnection) -> [DatabaseValue]? {
|
||||
return preupdate_getValues(
|
||||
preupdate_getValues(
|
||||
connection,
|
||||
sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in
|
||||
sqlite3_preupdate_old(connection, column, &value)
|
||||
@@ -1286,7 +1284,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
}
|
||||
|
||||
private func preupdate_getValues_new(_ connection: SQLiteConnection) -> [DatabaseValue]? {
|
||||
return preupdate_getValues(
|
||||
preupdate_getValues(
|
||||
connection,
|
||||
sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in
|
||||
sqlite3_preupdate_new(connection, column, &value)
|
||||
@@ -1303,12 +1301,10 @@ private struct CopiedDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl {
|
||||
let initialDatabaseValues: [DatabaseValue]?
|
||||
let finalDatabaseValues: [DatabaseValue]?
|
||||
|
||||
func initialDatabaseValue(atIndex index: Int) -> DatabaseValue? { return initialDatabaseValues?[index] }
|
||||
func finalDatabaseValue(atIndex index: Int) -> DatabaseValue? { return finalDatabaseValues?[index] }
|
||||
func initialDatabaseValue(atIndex index: Int) -> DatabaseValue? { initialDatabaseValues?[index] }
|
||||
func finalDatabaseValue(atIndex index: Int) -> DatabaseValue? { finalDatabaseValues?[index] }
|
||||
|
||||
func copy(_ event: DatabasePreUpdateEvent) -> DatabasePreUpdateEvent {
|
||||
return event
|
||||
}
|
||||
func copy(_ event: DatabasePreUpdateEvent) -> DatabasePreUpdateEvent { event }
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1363,7 +1359,7 @@ class SavepointStack {
|
||||
private var savepoints: [(name: String, index: Int)] = []
|
||||
|
||||
/// If true, there is no current save point.
|
||||
var isEmpty: Bool { return savepoints.isEmpty }
|
||||
var isEmpty: Bool { savepoints.isEmpty }
|
||||
|
||||
func clear() {
|
||||
eventsBuffer.removeAll()
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ public struct FTS3: VirtualTableModule {
|
||||
///
|
||||
/// See Database.create(virtualTable:using:)
|
||||
public func makeTableDefinition() -> FTS3TableDefinition {
|
||||
return FTS3TableDefinition()
|
||||
FTS3TableDefinition()
|
||||
}
|
||||
|
||||
/// Reserved; part of the VirtualTableModule protocol.
|
||||
|
||||
@@ -74,13 +74,13 @@ public struct FTS3Pattern {
|
||||
extension FTS3Pattern: DatabaseValueConvertible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawPattern.databaseValue
|
||||
rawPattern.databaseValue
|
||||
}
|
||||
|
||||
/// Returns an FTS3Pattern initialized from *dbValue*, if it contains
|
||||
/// a suitable value.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> FTS3Pattern? {
|
||||
return String
|
||||
String
|
||||
.fromDatabaseValue(dbValue)
|
||||
.flatMap { try? FTS3Pattern(rawPattern: $0) }
|
||||
}
|
||||
|
||||
@@ -89,14 +89,14 @@ public struct FTS3TokenizerDescriptor {
|
||||
}
|
||||
|
||||
func tokenize(_ string: String) -> [String] {
|
||||
return _tokenize(string)
|
||||
_tokenize(string)
|
||||
}
|
||||
|
||||
/// Returns an array of tokens found in the string argument.
|
||||
///
|
||||
/// FTS3TokenizerDescriptor.simple.tokenize("foo bar") // ["foo", "bar"]
|
||||
private func _tokenize(_ string: String) -> [String] {
|
||||
return DatabaseQueue().inDatabase { db in
|
||||
DatabaseQueue().inDatabase { db in
|
||||
var tokenizerChunks: [String] = []
|
||||
tokenizerChunks.append(name)
|
||||
for option in arguments {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public struct FTS4: VirtualTableModule {
|
||||
///
|
||||
/// See Database.create(virtualTable:using:)
|
||||
public func makeTableDefinition() -> FTS4TableDefinition {
|
||||
return FTS4TableDefinition()
|
||||
FTS4TableDefinition()
|
||||
}
|
||||
|
||||
/// Reserved; part of the VirtualTableModule protocol.
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public struct FTS5: VirtualTableModule {
|
||||
|
||||
/// Don't use this method.
|
||||
public func makeTableDefinition() -> FTS5TableDefinition {
|
||||
return FTS5TableDefinition()
|
||||
FTS5TableDefinition()
|
||||
}
|
||||
|
||||
/// Don't use this method.
|
||||
|
||||
@@ -39,7 +39,7 @@ extension FTS5CustomTokenizer {
|
||||
/// t.tokenizer = tokenizer
|
||||
/// }
|
||||
public static func tokenizerDescriptor(arguments: [String] = []) -> FTS5TokenizerDescriptor {
|
||||
return FTS5TokenizerDescriptor(components: [name] + arguments)
|
||||
FTS5TokenizerDescriptor(components: [name] + arguments)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -128,20 +128,20 @@ extension Database {
|
||||
/// try db.makeFTS5Pattern(rawPattern: "and", forTable: "document") // OK
|
||||
/// try db.makeFTS5Pattern(rawPattern: "AND", forTable: "document") // malformed MATCH expression: [AND]
|
||||
public func makeFTS5Pattern(rawPattern: String, forTable table: String) throws -> FTS5Pattern {
|
||||
return try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map(\.name))
|
||||
try FTS5Pattern(rawPattern: rawPattern, allowedColumns: columns(in: table).map(\.name))
|
||||
}
|
||||
}
|
||||
|
||||
extension FTS5Pattern: DatabaseValueConvertible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return rawPattern.databaseValue
|
||||
rawPattern.databaseValue
|
||||
}
|
||||
|
||||
/// Returns an FTS5Pattern initialized from *dbValue*, if it
|
||||
/// contains a suitable value.
|
||||
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> FTS5Pattern? {
|
||||
return String
|
||||
String
|
||||
.fromDatabaseValue(dbValue)
|
||||
.flatMap { try? FTS5Pattern(rawPattern: $0) }
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ extension FTS5Tokenizer {
|
||||
/// - .query: Tokenize like the search pattern of the MATCH operator.
|
||||
/// - parameter tokenizer: A FTS5TokenizerDescriptor such as .ascii()
|
||||
func tokenize(_ string: String, for tokenization: FTS5Tokenization) throws -> [(String, FTS5TokenFlags)] {
|
||||
return try ContiguousArray(string.utf8).withUnsafeBufferPointer { buffer -> [(String, FTS5TokenFlags)] in
|
||||
try ContiguousArray(string.utf8).withUnsafeBufferPointer { buffer -> [(String, FTS5TokenFlags)] in
|
||||
guard let addr = buffer.baseAddress else {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -23,12 +23,10 @@ public struct FTS5TokenizerDescriptor {
|
||||
///
|
||||
/// // "unicode61"
|
||||
/// FTS5TokenizerDescriptor.unicode61(removeDiacritics: false)).name
|
||||
var name: String {
|
||||
return components[0]
|
||||
}
|
||||
var name: String { components[0] }
|
||||
|
||||
var arguments: [String] {
|
||||
return Array(components.suffix(from: 1))
|
||||
Array(components.suffix(from: 1))
|
||||
}
|
||||
|
||||
/// Creates an FTS5 tokenizer descriptor.
|
||||
|
||||
@@ -190,7 +190,7 @@ public struct DatabaseMigrator {
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: An eventual database error.
|
||||
public func hasCompletedMigrations(_ db: Database) throws -> Bool {
|
||||
return try completedMigrations(db).last == migrations.last?.identifier
|
||||
try completedMigrations(db).last == migrations.last?.identifier
|
||||
}
|
||||
|
||||
// MARK: - Non public
|
||||
|
||||
@@ -37,7 +37,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func matching(_ pattern: FTS3Pattern?) -> QueryInterfaceRequest<Self> {
|
||||
return all().matching(pattern)
|
||||
all().matching(pattern)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,6 @@ extension ColumnExpression {
|
||||
/// If the search pattern is nil, SQLite will evaluate the expression
|
||||
/// to false.
|
||||
public func match(_ pattern: FTS3Pattern?) -> SQLExpression {
|
||||
return SQLExpressionBinary(.match, self, pattern ?? DatabaseValue.null)
|
||||
SQLExpressionBinary(.match, self, pattern ?? DatabaseValue.null)
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ extension TableRecord {
|
||||
/// If the search pattern is nil, the request does not match any
|
||||
/// database row.
|
||||
public static func matching(_ pattern: FTS5Pattern?) -> QueryInterfaceRequest<Self> {
|
||||
return all().matching(pattern)
|
||||
all().matching(pattern)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -46,33 +46,33 @@ public protocol Association: DerivableRequest {
|
||||
extension Association {
|
||||
/// :nodoc:
|
||||
public func _including(all association: SQLAssociation) -> Self {
|
||||
return mapDestinationRelation { $0._including(all: association) }
|
||||
mapDestinationRelation { $0._including(all: association) }
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _including(optional association: SQLAssociation) -> Self {
|
||||
return mapDestinationRelation { $0._including(optional: association) }
|
||||
mapDestinationRelation { $0._including(optional: association) }
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _including(required association: SQLAssociation) -> Self {
|
||||
return mapDestinationRelation { $0._including(required: association) }
|
||||
mapDestinationRelation { $0._including(required: association) }
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _joining(optional association: SQLAssociation) -> Self {
|
||||
return mapDestinationRelation { $0._joining(optional: association) }
|
||||
mapDestinationRelation { $0._joining(optional: association) }
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _joining(required association: SQLAssociation) -> Self {
|
||||
return mapDestinationRelation { $0._joining(required: association) }
|
||||
mapDestinationRelation { $0._joining(required: association) }
|
||||
}
|
||||
}
|
||||
|
||||
extension Association {
|
||||
private func mapDestinationRelation(_ transform: (SQLRelation) -> SQLRelation) -> Self {
|
||||
return .init(sqlAssociation: sqlAssociation.map(\.destination.relation, transform))
|
||||
.init(sqlAssociation: sqlAssociation.map(\.destination.relation, transform))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +102,7 @@ extension Association {
|
||||
/// for row in Row.fetchAll(db, request) {
|
||||
/// let team: Team = row["custom"]
|
||||
/// }
|
||||
var key: SQLAssociationKey {
|
||||
return sqlAssociation.destination.key
|
||||
}
|
||||
var key: SQLAssociationKey { sqlAssociation.destination.key }
|
||||
|
||||
/// Creates an association which selects *selection*.
|
||||
///
|
||||
@@ -128,7 +126,7 @@ extension Association {
|
||||
/// .select([Column("color")])
|
||||
/// var request = Player.including(required: association)
|
||||
public func select(_ selection: [SQLSelectable]) -> Self {
|
||||
return mapDestinationRelation { $0.select(selection) }
|
||||
mapDestinationRelation { $0.select(selection) }
|
||||
}
|
||||
|
||||
/// Creates an association which appends *selection*.
|
||||
@@ -145,7 +143,7 @@ extension Association {
|
||||
/// .annotated(with: [Column("name")])
|
||||
/// var request = Player.including(required: association)
|
||||
public func annotated(with selection: [SQLSelectable]) -> Self {
|
||||
return mapDestinationRelation { $0.annotated(with: selection) }
|
||||
mapDestinationRelation { $0.annotated(with: selection) }
|
||||
}
|
||||
|
||||
/// Creates an association with the provided *predicate promise* added to
|
||||
@@ -161,7 +159,7 @@ extension Association {
|
||||
/// let association = Player.team.filter { db in true }
|
||||
/// var request = Player.including(required: association)
|
||||
public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> Self {
|
||||
return mapDestinationRelation { $0.filter(predicate) }
|
||||
mapDestinationRelation { $0.filter(predicate) }
|
||||
}
|
||||
|
||||
/// Creates an association with the provided *orderings promise*.
|
||||
@@ -189,7 +187,7 @@ extension Association {
|
||||
/// .order{ _ in [Column("name")] }
|
||||
/// var request = Player.including(required: association)
|
||||
public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> Self {
|
||||
return mapDestinationRelation { $0.order(orderings) }
|
||||
mapDestinationRelation { $0.order(orderings) }
|
||||
}
|
||||
|
||||
/// Creates an association that reverses applied orderings.
|
||||
@@ -213,7 +211,7 @@ extension Association {
|
||||
/// let association = Player.team.reversed()
|
||||
/// var request = Player.including(required: association)
|
||||
public func reversed() -> Self {
|
||||
return mapDestinationRelation { $0.reversed() }
|
||||
mapDestinationRelation { $0.reversed() }
|
||||
}
|
||||
|
||||
/// Creates an association without any ordering.
|
||||
@@ -228,7 +226,7 @@ extension Association {
|
||||
/// let association = Player.team.order(Column("name")).unordered()
|
||||
/// var request = Player.including(required: association)
|
||||
public func unordered() -> Self {
|
||||
return mapDestinationRelation { $0.unordered() }
|
||||
mapDestinationRelation { $0.unordered() }
|
||||
}
|
||||
|
||||
/// Creates an association with the given key.
|
||||
@@ -254,7 +252,7 @@ extension Association {
|
||||
/// let playerInfos = PlayerInfo.all().fetchAll(db)
|
||||
/// print(playerInfos.first?.team)
|
||||
public func forKey(_ codingKey: CodingKey) -> Self {
|
||||
return forKey(codingKey.stringValue)
|
||||
forKey(codingKey.stringValue)
|
||||
}
|
||||
|
||||
/// Creates an association that allows you to define expressions that target
|
||||
@@ -286,14 +284,14 @@ extension Association {
|
||||
/// .including(required: Player.team.aliased(teamAlias))
|
||||
/// .filter(sql: "custom.color = ?", arguments: ["red"])
|
||||
public func aliased(_ alias: TableAlias) -> Self {
|
||||
return mapDestinationRelation { $0.qualified(with: alias) }
|
||||
mapDestinationRelation { $0.qualified(with: alias) }
|
||||
}
|
||||
}
|
||||
|
||||
// TableRequest
|
||||
extension Association {
|
||||
/// :nodoc:
|
||||
public var databaseTableName: String { return RowDecoder.databaseTableName }
|
||||
public var databaseTableName: String { RowDecoder.databaseTableName }
|
||||
}
|
||||
|
||||
// MARK: - AssociationToOne
|
||||
@@ -326,7 +324,7 @@ extension AssociationToMany {
|
||||
|
||||
extension AssociationToMany {
|
||||
private func makeAggregate(_ expression: SQLExpression) -> AssociationAggregate<OriginRowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let tableAlias = TableAlias()
|
||||
let request = request
|
||||
.joining(optional: self.aliased(tableAlias))
|
||||
@@ -352,7 +350,7 @@ extension AssociationToMany {
|
||||
///
|
||||
/// let teams: [Team] = try Team.having(Team.players.count() > 10).fetchAll(db)
|
||||
public var count: AssociationAggregate<OriginRowDecoder> {
|
||||
return makeAggregate(SQLExpressionCountDistinct(Column.rowID))
|
||||
makeAggregate(SQLExpressionCountDistinct(Column.rowID))
|
||||
.forKey("\(key.singularizedName)Count")
|
||||
}
|
||||
|
||||
@@ -372,7 +370,7 @@ extension AssociationToMany {
|
||||
/// let teams: [Team] = try Team.having(!Team.players.isEmpty())
|
||||
/// let teams: [Team] = try Team.having(Team.players.isEmpty() == false)
|
||||
public var isEmpty: AssociationAggregate<OriginRowDecoder> {
|
||||
return makeAggregate(SQLExpressionIsEmpty(SQLExpressionCountDistinct(Column.rowID)))
|
||||
makeAggregate(SQLExpressionIsEmpty(SQLExpressionCountDistinct(Column.rowID)))
|
||||
.forKey("hasNo\(key.singularizedName.uppercasingFirstCharacter)")
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ extension AssociationAggregate: KeyPathRefining {
|
||||
/// let numberOfBooks: Int = row["numberOfBooks"]
|
||||
/// }
|
||||
public func forKey(_ key: String) -> AssociationAggregate<RowDecoder> {
|
||||
return with(\.key, key)
|
||||
with(\.key, key)
|
||||
}
|
||||
|
||||
/// Returns an aggregate that is selected in a column named like the given
|
||||
@@ -100,7 +100,7 @@ extension AssociationAggregate: KeyPathRefining {
|
||||
/// }
|
||||
/// }
|
||||
public func forKey(_ key: CodingKey) -> AssociationAggregate<RowDecoder> {
|
||||
return forKey(key.stringValue)
|
||||
forKey(key.stringValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ extension AssociationAggregate: KeyPathRefining {
|
||||
///
|
||||
/// Author.having(!Author.books.isEmpty)
|
||||
public prefix func ! <RowDecoder>(aggregate: AssociationAggregate<RowDecoder>) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = aggregate.prepare(request)
|
||||
return (request: request, expression: !expression)
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public func == <RowDecoder>(
|
||||
///
|
||||
/// Author.having(Author.books.isEmpty == false)
|
||||
public func == <RowDecoder>(lhs: AssociationAggregate<RowDecoder>, rhs: Bool) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = lhs.prepare(request)
|
||||
return (request: request, expression: expression == rhs)
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public func == <RowDecoder>(lhs: AssociationAggregate<RowDecoder>, rhs: Bool) ->
|
||||
///
|
||||
/// Author.having(false == Author.books.isEmpty)
|
||||
public func == <RowDecoder>(lhs: Bool, rhs: AssociationAggregate<RowDecoder>) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = rhs.prepare(request)
|
||||
return (request: request, expression: lhs == expression)
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public func != <RowDecoder>(
|
||||
///
|
||||
/// Author.having(Author.books.isEmpty != true)
|
||||
public func != <RowDecoder>(lhs: AssociationAggregate<RowDecoder>, rhs: Bool) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = lhs.prepare(request)
|
||||
return (request: request, expression: expression != rhs)
|
||||
}
|
||||
@@ -347,7 +347,7 @@ public func != <RowDecoder>(lhs: AssociationAggregate<RowDecoder>, rhs: Bool) ->
|
||||
///
|
||||
/// Author.having(true != Author.books.isEmpty)
|
||||
public func != <RowDecoder>(lhs: Bool, rhs: AssociationAggregate<RowDecoder>) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = rhs.prepare(request)
|
||||
return (request: request, expression: lhs != expression)
|
||||
}
|
||||
@@ -657,7 +657,7 @@ public func >= <RowDecoder>(
|
||||
///
|
||||
/// Author.annotated(with: -Author.books.count)
|
||||
public prefix func - <RowDecoder>(aggregate: AssociationAggregate<RowDecoder>) -> AssociationAggregate<RowDecoder> {
|
||||
return AssociationAggregate { request in
|
||||
AssociationAggregate { request in
|
||||
let (request, expression) = aggregate.prepare(request)
|
||||
return (request: request, expression:-expression)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ extension QueryInterfaceRequest where RowDecoder: TableRecord {
|
||||
/// var request = Player.all()
|
||||
/// request = request.annotated(with: Player.books.count)
|
||||
public func annotated(with aggregates: AssociationAggregate<RowDecoder>...) -> QueryInterfaceRequest {
|
||||
return annotated(with: aggregates)
|
||||
annotated(with: aggregates)
|
||||
}
|
||||
|
||||
/// Creates a request which appends *aggregates* to the current selection.
|
||||
@@ -28,7 +28,7 @@ extension QueryInterfaceRequest where RowDecoder: TableRecord {
|
||||
/// var request = Player.all()
|
||||
/// request = request.annotated(with: [Player.books.count])
|
||||
public func annotated(with aggregates: [AssociationAggregate<RowDecoder>]) -> QueryInterfaceRequest {
|
||||
return aggregates.reduce(self) { request, aggregate in
|
||||
aggregates.reduce(self) { request, aggregate in
|
||||
request.annotated(with: aggregate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ extension QueryInterfaceRequest: FetchRequest {
|
||||
/// - parameter db: A database connection.
|
||||
/// :nodoc:
|
||||
public func fetchCount(_ db: Database) throws -> Int {
|
||||
return try query.fetchCount(db)
|
||||
try query.fetchCount(db)
|
||||
}
|
||||
|
||||
/// Returns the database region that the request looks into.
|
||||
@@ -132,7 +132,7 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
/// .select([Column("id")])
|
||||
/// .select([Column("email")])
|
||||
public func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.select(selection) })
|
||||
map(\.query, { $0.select(selection) })
|
||||
}
|
||||
|
||||
/// Creates a request which selects *selection*, and fetches values of
|
||||
@@ -223,7 +223,7 @@ extension QueryInterfaceRequest: SelectionRequest {
|
||||
/// .select([Column("id"), Column("email")])
|
||||
/// .annotated(with: [Column("name")])
|
||||
public func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.annotated(with: selection) })
|
||||
map(\.query, { $0.annotated(with: selection) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ extension QueryInterfaceRequest: FilteredRequest {
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter { db in true }
|
||||
public func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.filter(predicate) })
|
||||
map(\.query, { $0.filter(predicate) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ extension QueryInterfaceRequest: OrderedRequest {
|
||||
/// .reversed()
|
||||
/// .order{ _ in [Column("name")] }
|
||||
public func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.order(orderings) })
|
||||
map(\.query, { $0.order(orderings) })
|
||||
}
|
||||
|
||||
/// Creates a request that reverses applied orderings.
|
||||
@@ -273,7 +273,7 @@ extension QueryInterfaceRequest: OrderedRequest {
|
||||
/// var request = Player.all()
|
||||
/// request = request.reversed()
|
||||
public func reversed() -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.reversed() })
|
||||
map(\.query, { $0.reversed() })
|
||||
}
|
||||
|
||||
/// Creates a request without any ordering.
|
||||
@@ -282,7 +282,7 @@ extension QueryInterfaceRequest: OrderedRequest {
|
||||
/// var request = Player.all().order(Column("name"))
|
||||
/// request = request.unordered()
|
||||
public func unordered() -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.unordered() })
|
||||
map(\.query, { $0.unordered() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,40 +291,40 @@ extension QueryInterfaceRequest: AggregatingRequest {
|
||||
|
||||
/// Creates a request grouped according to *expressions promise*.
|
||||
public func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.group(expressions) })
|
||||
map(\.query, { $0.group(expressions) })
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func having(_ predicate: SQLExpressible) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.having(predicate) })
|
||||
map(\.query, { $0.having(predicate) })
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest: _JoinableRequest {
|
||||
/// :nodoc:
|
||||
public func _including(all association: SQLAssociation) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0._including(all: association) })
|
||||
map(\.query, { $0._including(all: association) })
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _including(optional association: SQLAssociation) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0._including(optional: association) })
|
||||
map(\.query, { $0._including(optional: association) })
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _including(required association: SQLAssociation) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0._including(required: association) })
|
||||
map(\.query, { $0._including(required: association) })
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _joining(optional association: SQLAssociation) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0._joining(optional: association) })
|
||||
map(\.query, { $0._joining(optional: association) })
|
||||
}
|
||||
|
||||
/// :nodoc:
|
||||
public func _joining(required association: SQLAssociation) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0._joining(required: association) })
|
||||
map(\.query, { $0._joining(required: association) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +344,7 @@ extension QueryInterfaceRequest: KeyPathRefining {
|
||||
/// var request = Player.select(Column("name"))
|
||||
/// request = request.distinct()
|
||||
public func distinct() -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.distinct() })
|
||||
map(\.query, { $0.distinct() })
|
||||
}
|
||||
|
||||
/// Creates a request which expects a single result.
|
||||
@@ -355,7 +355,7 @@ extension QueryInterfaceRequest: KeyPathRefining {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func expectingSingleResult() -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.expectingSingleResult() })
|
||||
map(\.query, { $0.expectingSingleResult() })
|
||||
}
|
||||
|
||||
|
||||
@@ -367,7 +367,7 @@ extension QueryInterfaceRequest: KeyPathRefining {
|
||||
///
|
||||
/// Any previous limit is replaced.
|
||||
public func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.limit(limit, offset: offset) })
|
||||
map(\.query, { $0.limit(limit, offset: offset) })
|
||||
}
|
||||
|
||||
/// Creates a request that allows you to define expressions that target
|
||||
@@ -388,7 +388,7 @@ extension QueryInterfaceRequest: KeyPathRefining {
|
||||
/// .aliased(playerAlias)
|
||||
/// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
|
||||
public func aliased(_ alias: TableAlias) -> QueryInterfaceRequest {
|
||||
return map(\.query, { $0.qualified(with: alias) })
|
||||
map(\.query, { $0.qualified(with: alias) })
|
||||
}
|
||||
|
||||
/// Creates a request bound to type Target.
|
||||
@@ -405,7 +405,7 @@ extension QueryInterfaceRequest: KeyPathRefining {
|
||||
/// - parameter type: The fetched type Target
|
||||
/// - returns: A typed request bound to type Target.
|
||||
public func asRequest<RowDecoder>(of type: RowDecoder.Type) -> QueryInterfaceRequest<RowDecoder> {
|
||||
return QueryInterfaceRequest<RowDecoder>(query: query)
|
||||
QueryInterfaceRequest<RowDecoder>(query: query)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -613,7 +613,7 @@ extension Array where Element == Row {
|
||||
extension Row {
|
||||
/// - precondition: Columns all exist in the row.
|
||||
fileprivate func indexes(ofColumns columns: [String]) -> [Int] {
|
||||
return columns.map { column -> Int in
|
||||
columns.map { column -> Int in
|
||||
guard let index = index(ofColumn: column) else {
|
||||
fatalError("Column \(column) is not selected")
|
||||
}
|
||||
@@ -658,7 +658,7 @@ public struct ColumnAssignment {
|
||||
/// try Player.updateAll(db, Column("score") <- 0)
|
||||
/// }
|
||||
public func <- (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment {
|
||||
return ColumnAssignment(column: column, value: value)
|
||||
ColumnAssignment(column: column, value: value)
|
||||
}
|
||||
|
||||
/// Creates an assignment that adds a value
|
||||
@@ -671,7 +671,7 @@ public func <- (column: ColumnExpression, value: SQLExpressible) -> ColumnAssign
|
||||
/// try Player.updateAll(db, Column("score") += 1)
|
||||
/// }
|
||||
public func += (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment {
|
||||
return column <- column + value
|
||||
column <- column + value
|
||||
}
|
||||
|
||||
/// Creates an assignment that subtracts a value
|
||||
@@ -684,7 +684,7 @@ public func += (column: ColumnExpression, value: SQLExpressible) -> ColumnAssign
|
||||
/// try Player.updateAll(db, Column("score") -= 1)
|
||||
/// }
|
||||
public func -= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment {
|
||||
return column <- column - value
|
||||
column <- column - value
|
||||
}
|
||||
|
||||
/// Creates an assignment that multiplies by a value
|
||||
@@ -697,7 +697,7 @@ public func -= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssign
|
||||
/// try Player.updateAll(db, Column("score") *= 2)
|
||||
/// }
|
||||
public func *= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment {
|
||||
return column <- column * value
|
||||
column <- column * value
|
||||
}
|
||||
|
||||
/// Creates an assignment that divides by a value
|
||||
@@ -710,5 +710,5 @@ public func *= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssign
|
||||
/// try Player.updateAll(db, Column("score") /= 2)
|
||||
/// }
|
||||
public func /= (column: ColumnExpression, value: SQLExpressible) -> ColumnAssignment {
|
||||
return column <- column / value
|
||||
column <- column / value
|
||||
}
|
||||
@@ -45,7 +45,7 @@ extension SelectionRequest {
|
||||
/// .select(Column("id"))
|
||||
/// .select(Column("email"))
|
||||
public func select(_ selection: SQLSelectable...) -> Self {
|
||||
return select(selection)
|
||||
select(selection)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
@@ -61,7 +61,7 @@ extension SelectionRequest {
|
||||
/// .select(sql: "id")
|
||||
/// .select(sql: "email")
|
||||
public func select(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return select(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
select(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request which selects an SQL *literal*.
|
||||
@@ -102,7 +102,7 @@ extension SelectionRequest {
|
||||
/// .select([Column("id"), Column("email")])
|
||||
/// .annotated(with: Column("name"))
|
||||
public func annotated(with selection: SQLSelectable...) -> Self {
|
||||
return annotated(with: selection)
|
||||
annotated(with: selection)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public protocol FilteredRequest {
|
||||
/// :nodoc:
|
||||
extension FilteredRequest {
|
||||
public func expectingSingleResult() -> Self {
|
||||
return self
|
||||
self
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
@@ -145,7 +145,7 @@ extension FilteredRequest {
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter(Column("email") == "arthur@example.com")
|
||||
public func filter(_ predicate: SQLExpressible) -> Self {
|
||||
return filter { _ in predicate }
|
||||
filter { _ in predicate }
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
@@ -155,7 +155,7 @@ extension FilteredRequest {
|
||||
/// var request = Player.all()
|
||||
/// request = request.filter(sql: "email = ?", arguments: ["arthur@example.com"])
|
||||
public func filter(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return filter(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
filter(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate* added to the
|
||||
@@ -183,7 +183,7 @@ extension FilteredRequest {
|
||||
/// var request = Player.all()
|
||||
/// request = request.none()
|
||||
public func none() -> Self {
|
||||
return filter(false)
|
||||
filter(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,17 +353,17 @@ public protocol AggregatingRequest {
|
||||
extension AggregatingRequest {
|
||||
/// Creates a request grouped according to *expressions*.
|
||||
public func group(_ expressions: [SQLExpressible]) -> Self {
|
||||
return group { _ in expressions }
|
||||
group { _ in expressions }
|
||||
}
|
||||
|
||||
/// Creates a request grouped according to *expressions*.
|
||||
public func group(_ expressions: SQLExpressible...) -> Self {
|
||||
return group(expressions)
|
||||
group(expressions)
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
public func group(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return group(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
group(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with a new grouping.
|
||||
@@ -375,7 +375,7 @@ extension AggregatingRequest {
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func having(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return having(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
having(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *sql* added to the
|
||||
@@ -446,7 +446,7 @@ extension OrderedRequest {
|
||||
/// .reversed()
|
||||
/// .order(Column("name"))
|
||||
public func order(_ orderings: SQLOrderingTerm...) -> Self {
|
||||
return order { _ in orderings }
|
||||
order { _ in orderings }
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *orderings*.
|
||||
@@ -463,7 +463,7 @@ extension OrderedRequest {
|
||||
/// .reversed()
|
||||
/// .order(Column("name"))
|
||||
public func order(_ orderings: [SQLOrderingTerm]) -> Self {
|
||||
return order { _ in orderings }
|
||||
order { _ in orderings }
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to *sql*.
|
||||
@@ -479,7 +479,7 @@ extension OrderedRequest {
|
||||
/// .order(sql: "email")
|
||||
/// .order(sql: "name")
|
||||
public func order(sql: String, arguments: StatementArguments = StatementArguments()) -> Self {
|
||||
return order(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
order(literal: SQLLiteral(sql: sql, arguments: arguments))
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to an SQL *literal*.
|
||||
@@ -556,35 +556,35 @@ public protocol JoinableRequest: _JoinableRequest {
|
||||
extension JoinableRequest {
|
||||
/// Creates a request that prefetches an association.
|
||||
public func including<A: AssociationToMany>(all association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
return _including(all: association.sqlAssociation)
|
||||
_including(all: association.sqlAssociation)
|
||||
}
|
||||
|
||||
/// Creates a request that includes an association. The columns of the
|
||||
/// associated record are selected. The returned request does not
|
||||
/// require that the associated database table contains a matching row.
|
||||
public func including<A: Association>(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
return _including(optional: association.sqlAssociation)
|
||||
_including(optional: association.sqlAssociation)
|
||||
}
|
||||
|
||||
/// Creates a request that includes an association. The columns of the
|
||||
/// associated record are selected. The returned request requires
|
||||
/// that the associated database table contains a matching row.
|
||||
public func including<A: Association>(required association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
return _including(required: association.sqlAssociation)
|
||||
_including(required: association.sqlAssociation)
|
||||
}
|
||||
|
||||
/// Creates a request that joins an association. The columns of the
|
||||
/// associated record are not selected. The returned request does not
|
||||
/// require that the associated database table contains a matching row.
|
||||
public func joining<A: Association>(optional association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
return _joining(optional: association.sqlAssociation)
|
||||
_joining(optional: association.sqlAssociation)
|
||||
}
|
||||
|
||||
/// Creates a request that joins an association. The columns of the
|
||||
/// associated record are not selected. The returned request requires
|
||||
/// that the associated database table contains a matching row.
|
||||
public func joining<A: Association>(required association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
return _joining(required: association.sqlAssociation)
|
||||
_joining(required: association.sqlAssociation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,13 @@ extension ColumnExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String {
|
||||
return name.quotedDatabaseIdentifier
|
||||
name.quotedDatabaseIdentifier
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return QualifiedColumn(name, alias: alias)
|
||||
QualifiedColumn(name, alias: alias)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,5 @@ struct QualifiedColumn: ColumnExpression {
|
||||
/// }
|
||||
/// }
|
||||
extension ColumnExpression where Self: RawRepresentable, Self.RawValue == String {
|
||||
public var name: String {
|
||||
return rawValue
|
||||
}
|
||||
public var name: String { rawValue }
|
||||
}
|
||||
@@ -37,13 +37,13 @@ struct DatabasePromise<T> {
|
||||
|
||||
/// Returns a promise whose value is transformed by the given closure.
|
||||
func map<U>(_ transform: @escaping (T) throws -> U) -> DatabasePromise<U> {
|
||||
return DatabasePromise<U> { db in
|
||||
DatabasePromise<U> { db in
|
||||
try transform(self.resolve(db))
|
||||
}
|
||||
}
|
||||
|
||||
func flatMap<U>(_ transform: @escaping (T) -> DatabasePromise<U>) -> DatabasePromise<U> {
|
||||
return DatabasePromise<U> { db in
|
||||
DatabasePromise<U> { db in
|
||||
try transform(self.resolve(db)).resolve(db)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,17 +54,15 @@
|
||||
public /* TODO: internal */ struct SQLAssociation {
|
||||
// All steps, from pivot to destination. Never empty.
|
||||
private(set) var steps: [SQLAssociationStep]
|
||||
var keyPath: [String] {
|
||||
return steps.map(\.keyName)
|
||||
}
|
||||
var keyPath: [String] { steps.map(\.keyName) }
|
||||
|
||||
var destination: SQLAssociationStep {
|
||||
get { return steps[steps.count - 1] }
|
||||
get { steps[steps.count - 1] }
|
||||
set { steps[steps.count - 1] = newValue }
|
||||
}
|
||||
|
||||
var pivot: SQLAssociationStep {
|
||||
get { return steps[0] }
|
||||
get { steps[0] }
|
||||
set { steps[0] = newValue }
|
||||
}
|
||||
|
||||
@@ -89,12 +87,12 @@ public /* TODO: internal */ struct SQLAssociation {
|
||||
|
||||
/// Changes the destination key
|
||||
func forDestinationKey(_ key: SQLAssociationKey) -> SQLAssociation {
|
||||
return with(\.destination.key, key)
|
||||
with(\.destination.key, key)
|
||||
}
|
||||
|
||||
/// Returns a new association
|
||||
func through(_ other: SQLAssociation) -> SQLAssociation {
|
||||
return SQLAssociation(steps: other.steps + steps)
|
||||
SQLAssociation(steps: other.steps + steps)
|
||||
}
|
||||
|
||||
/// Given an origin alias and rows, returns the destination of the
|
||||
@@ -205,9 +203,7 @@ struct SQLAssociationStep: KeyPathRefining {
|
||||
var relation: SQLRelation
|
||||
var cardinality: SQLAssociationCardinality
|
||||
|
||||
var keyName: String {
|
||||
return key.name(for: cardinality)
|
||||
}
|
||||
var keyName: String { key.name(for: cardinality) }
|
||||
}
|
||||
|
||||
enum SQLAssociationCardinality {
|
||||
|
||||
@@ -25,7 +25,7 @@ public struct SQLCollatedExpression {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var asc: SQLOrderingTerm {
|
||||
return SQLOrdering.asc(sqlExpression)
|
||||
SQLOrdering.asc(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an ordering suitable for QueryInterfaceRequest.order()
|
||||
@@ -37,7 +37,7 @@ public struct SQLCollatedExpression {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var desc: SQLOrderingTerm {
|
||||
return SQLOrdering.desc(sqlExpression)
|
||||
SQLOrdering.desc(sqlExpression)
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
@@ -50,7 +50,7 @@ public struct SQLCollatedExpression {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var ascNullsLast: SQLOrderingTerm {
|
||||
return SQLOrdering.ascNullsLast(sqlExpression)
|
||||
SQLOrdering.ascNullsLast(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an ordering suitable for QueryInterfaceRequest.order()
|
||||
@@ -62,7 +62,7 @@ public struct SQLCollatedExpression {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var descNullsFirst: SQLOrderingTerm {
|
||||
return SQLOrdering.descNullsFirst(sqlExpression)
|
||||
SQLOrdering.descNullsFirst(sqlExpression)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -72,7 +72,7 @@ public struct SQLCollatedExpression {
|
||||
}
|
||||
|
||||
var sqlExpression: SQLExpression {
|
||||
return SQLExpressionCollate(expression, collationName: collationName)
|
||||
SQLExpressionCollate(expression, collationName: collationName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,18 +82,18 @@ extension SQLCollatedExpression: SQLOrderingTerm {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var reversed: SQLOrderingTerm {
|
||||
return desc
|
||||
desc
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlExpression.orderingTermSQL(&context)
|
||||
sqlExpression.orderingTermSQL(&context)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
|
||||
return SQLCollatedExpression(expression.qualifiedExpression(with: alias), collationName: collationName)
|
||||
SQLCollatedExpression(expression.qualifiedExpression(with: alias), collationName: collationName)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ extension SQLCollection {
|
||||
///
|
||||
/// Returns a SQLExpressionContains which applies the `IN` SQL operator.
|
||||
public func contains(_ value: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionContains(value, self)
|
||||
SQLExpressionContains(value, self)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ struct SQLExpressionsArray: SQLCollection {
|
||||
}
|
||||
|
||||
func collectionSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return expressions
|
||||
expressions
|
||||
.map { $0.expressionSQL(&context, wrappedInParenthesis: false) }
|
||||
.joined(separator: ", ")
|
||||
}
|
||||
|
||||
@@ -59,13 +59,13 @@ extension SQLExpressible where Self: SQLOrderingTerm {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var reversed: SQLOrderingTerm {
|
||||
return SQLOrdering.desc(sqlExpression)
|
||||
SQLOrdering.desc(sqlExpression)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func orderingTermSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,24 +76,24 @@ extension SQLExpressible where Self: SQLSelectable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func countedSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
sqlExpression.expressionSQL(&context, wrappedInParenthesis: false)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func count(distinct: Bool) -> SQLCount? {
|
||||
return sqlExpression.count(distinct: distinct)
|
||||
sqlExpression.count(distinct: distinct)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func columnCount(_ db: Database) throws -> Int {
|
||||
return 1
|
||||
1
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public struct SQLExpressionUnary: SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionUnary(op, expression.qualifiedExpression(with: alias))
|
||||
SQLExpressionUnary(op, expression.qualifiedExpression(with: alias))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public struct SQLExpressionBinary: SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionBinary(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
|
||||
SQLExpressionBinary(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ struct SQLExpressionBinaryReduce: SQLExpression {
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(op, expressions.map { $0.qualifiedExpression(with: alias) })
|
||||
SQLExpressionBinaryReduce(op, expressions.map { $0.qualifiedExpression(with: alias) })
|
||||
}
|
||||
|
||||
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
|
||||
@@ -343,7 +343,7 @@ extension Sequence where Element == SQLExpression {
|
||||
/// // SELECT * FROM player WHERE 0
|
||||
/// Player.filter([].joined(operator: .or))
|
||||
public func joined(operator: SQLAssociativeBinaryOperator) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(`operator`, Array(self))
|
||||
SQLExpressionBinaryReduce(`operator`, Array(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,11 +388,11 @@ struct SQLExpressionEqual: SQLExpression {
|
||||
}
|
||||
|
||||
var negated: SQLExpression {
|
||||
return SQLExpressionEqual(op.negated, lhs, rhs)
|
||||
SQLExpressionEqual(op.negated, lhs, rhs)
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionEqual(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
|
||||
SQLExpressionEqual(op, lhs.qualifiedExpression(with: alias), rhs.qualifiedExpression(with: alias))
|
||||
}
|
||||
|
||||
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
|
||||
@@ -459,11 +459,11 @@ struct SQLExpressionContains: SQLExpression {
|
||||
}
|
||||
|
||||
var negated: SQLExpression {
|
||||
return SQLExpressionContains(expression, collection, negated: !isNegated)
|
||||
SQLExpressionContains(expression, collection, negated: !isNegated)
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated)
|
||||
SQLExpressionContains(expression.qualifiedExpression(with: alias), collection, negated: isNegated)
|
||||
}
|
||||
|
||||
func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
|
||||
@@ -529,11 +529,11 @@ struct SQLExpressionBetween: SQLExpression {
|
||||
}
|
||||
|
||||
var negated: SQLExpression {
|
||||
return SQLExpressionBetween(expression, lowerBound, upperBound, negated: !isNegated)
|
||||
SQLExpressionBetween(expression, lowerBound, upperBound, negated: !isNegated)
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionBetween(
|
||||
SQLExpressionBetween(
|
||||
expression.qualifiedExpression(with: alias),
|
||||
lowerBound.qualifiedExpression(with: alias),
|
||||
upperBound.qualifiedExpression(with: alias),
|
||||
@@ -621,7 +621,7 @@ public struct SQLExpressionFunction: SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionFunction(functionName, arguments: arguments.map { $0.qualifiedExpression(with: alias) })
|
||||
SQLExpressionFunction(functionName, arguments: arguments.map { $0.qualifiedExpression(with: alias) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,11 +640,11 @@ struct SQLExpressionCount: SQLExpression {
|
||||
}
|
||||
|
||||
func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String {
|
||||
return "COUNT(" + counted.countedSQL(&context) + ")"
|
||||
"COUNT(" + counted.countedSQL(&context) + ")"
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionCount(counted.qualifiedSelectable(with: alias))
|
||||
SQLExpressionCount(counted.qualifiedSelectable(with: alias))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,11 +662,11 @@ struct SQLExpressionCountDistinct: SQLExpression {
|
||||
}
|
||||
|
||||
func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String {
|
||||
return "COUNT(DISTINCT " + counted.expressionSQL(&context, wrappedInParenthesis: false) + ")"
|
||||
"COUNT(DISTINCT " + counted.expressionSQL(&context, wrappedInParenthesis: false) + ")"
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionCountDistinct(counted.qualifiedExpression(with: alias))
|
||||
SQLExpressionCountDistinct(counted.qualifiedExpression(with: alias))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ struct SQLExpressionIsEmpty: SQLExpression {
|
||||
}
|
||||
|
||||
var negated: SQLExpression {
|
||||
return SQLExpressionIsEmpty(countExpression, isEmpty: !isEmpty)
|
||||
SQLExpressionIsEmpty(countExpression, isEmpty: !isEmpty)
|
||||
}
|
||||
|
||||
func expressionSQL(_ context: inout SQLGenerationContext, wrappedInParenthesis: Bool) -> String {
|
||||
@@ -700,7 +700,7 @@ struct SQLExpressionIsEmpty: SQLExpression {
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionIsEmpty(countExpression.qualifiedExpression(with: alias), isEmpty: isEmpty)
|
||||
SQLExpressionIsEmpty(countExpression.qualifiedExpression(with: alias), isEmpty: isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,7 +722,7 @@ struct TableMatchExpression: SQLExpression {
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return TableMatchExpression(
|
||||
TableMatchExpression(
|
||||
alias: self.alias,
|
||||
pattern: pattern.qualifiedExpression(with: alias))
|
||||
}
|
||||
@@ -755,6 +755,6 @@ struct SQLExpressionCollate: SQLExpression {
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionCollate(expression.qualifiedExpression(with: alias), collationName: collationName)
|
||||
SQLExpressionCollate(expression.qualifiedExpression(with: alias), collationName: collationName)
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ extension SQLExpression {
|
||||
///
|
||||
/// :nodoc:
|
||||
public var negated: SQLExpression {
|
||||
return SQLExpressionNot(self)
|
||||
SQLExpressionNot(self)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -63,7 +63,7 @@ extension SQLExpression {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func matchedRowIds(rowIdName: String?) -> Set<Int64>? {
|
||||
return nil
|
||||
nil
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -72,7 +72,7 @@ extension SQLExpression {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
|
||||
return qualifiedExpression(with: alias)
|
||||
qualifiedExpression(with: alias)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -81,7 +81,7 @@ extension SQLExpression {
|
||||
///
|
||||
/// :nodoc:
|
||||
public func qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
|
||||
return qualifiedExpression(with: alias)
|
||||
qualifiedExpression(with: alias)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ extension SQLExpression {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public var sqlExpression: SQLExpression {
|
||||
return self
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,10 +134,10 @@ struct SQLExpressionNot: SQLExpression {
|
||||
}
|
||||
|
||||
var negated: SQLExpression {
|
||||
return expression
|
||||
expression
|
||||
}
|
||||
|
||||
func qualifiedExpression(with alias: TableAlias) -> SQLExpression {
|
||||
return SQLExpressionNot(expression.qualifiedExpression(with: alias))
|
||||
SQLExpressionNot(expression.qualifiedExpression(with: alias))
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ extension DatabaseFunction {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-functions
|
||||
public func callAsFunction(_ arguments: SQLExpressible...) -> SQLExpression {
|
||||
return SQLExpressionFunction(SQLFunctionName(name), arguments: arguments.map(\.sqlExpression))
|
||||
SQLExpressionFunction(SQLFunctionName(name), arguments: arguments.map(\.sqlExpression))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ extension SQLFunctionName {
|
||||
/// // ABS(amount)
|
||||
/// abs(Column("amount"))
|
||||
public func abs(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.abs, arguments: value)
|
||||
SQLExpressionFunction(.abs, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ extension SQLFunctionName {
|
||||
/// // AVG(length)
|
||||
/// average(Column("length"))
|
||||
public func average(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.avg, arguments: value)
|
||||
SQLExpressionFunction(.avg, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public func average(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
/// // COUNT(email)
|
||||
/// count(Column("email"))
|
||||
public func count(_ counted: SQLSelectable) -> SQLExpression {
|
||||
return SQLExpressionCount(counted)
|
||||
SQLExpressionCount(counted)
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public func count(_ counted: SQLSelectable) -> SQLExpression {
|
||||
/// // COUNT(DISTINCT email)
|
||||
/// count(distinct: Column("email"))
|
||||
public func count(distinct value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionCountDistinct(value.sqlExpression)
|
||||
SQLExpressionCountDistinct(value.sqlExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ extension SQLFunctionName {
|
||||
/// // IFNULL(name, 'Anonymous')
|
||||
/// Column("name") ?? "Anonymous"
|
||||
public func ?? (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.ifNull, arguments: lhs, rhs)
|
||||
SQLExpressionFunction(.ifNull, arguments: lhs, rhs)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ extension SQLFunctionName {
|
||||
/// // LENGTH(name)
|
||||
/// length(Column("name"))
|
||||
public func length(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.length, arguments: value)
|
||||
SQLExpressionFunction(.length, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ extension SQLFunctionName {
|
||||
/// // MAX(score)
|
||||
/// max(Column("score"))
|
||||
public func max(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.max, arguments: value)
|
||||
SQLExpressionFunction(.max, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ extension SQLFunctionName {
|
||||
/// // MIN(score)
|
||||
/// min(Column("score"))
|
||||
public func min(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.min, arguments: value)
|
||||
SQLExpressionFunction(.min, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ extension SQLFunctionName {
|
||||
/// // SUM(amount)
|
||||
/// sum(Column("amount"))
|
||||
public func sum(_ value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionFunction(.sum, arguments: value)
|
||||
SQLExpressionFunction(.sum, arguments: value)
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.capitalized)
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var capitalized: SQLExpression {
|
||||
return DatabaseFunction.capitalize(sqlExpression)
|
||||
DatabaseFunction.capitalize(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -165,7 +165,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.lowercased())
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var lowercased: SQLExpression {
|
||||
return DatabaseFunction.lowercase(sqlExpression)
|
||||
DatabaseFunction.lowercase(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -175,7 +175,7 @@ extension SQLSpecificExpressible {
|
||||
/// let request = Player.select(nameColumn.uppercased())
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
public var uppercased: SQLExpression {
|
||||
return DatabaseFunction.uppercase(sqlExpression)
|
||||
DatabaseFunction.uppercase(sqlExpression)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedCapitalized: SQLExpression {
|
||||
return DatabaseFunction.localizedCapitalize(sqlExpression)
|
||||
DatabaseFunction.localizedCapitalize(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -200,7 +200,7 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedLowercased: SQLExpression {
|
||||
return DatabaseFunction.localizedLowercase(sqlExpression)
|
||||
DatabaseFunction.localizedLowercase(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that applies the Swift's built-in
|
||||
@@ -211,6 +211,6 @@ extension SQLSpecificExpressible {
|
||||
/// let names = try String.fetchAll(dbQueue, request) // [String]
|
||||
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
|
||||
public var localizedUppercased: SQLExpression {
|
||||
return DatabaseFunction.localizedUppercase(sqlExpression)
|
||||
DatabaseFunction.localizedUppercase(sqlExpression)
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ private func isEqual(_ lhs: SQLExpression, _ rhs: SQLExpression) -> SQLExpressio
|
||||
/// // name IS NULL
|
||||
/// Column("name") == nil
|
||||
public func == (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return isEqual(lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
isEqual(lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `=` SQL operator.
|
||||
@@ -45,7 +45,7 @@ public func == (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpress
|
||||
/// // name IS NULL
|
||||
/// Column("name").collating(.nocase) == nil
|
||||
public func == (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression == rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression == rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the boolean value of an expression.
|
||||
@@ -75,7 +75,7 @@ public func == (lhs: SQLSpecificExpressible, rhs: Bool) -> SQLExpression {
|
||||
/// // name IS NULL
|
||||
/// nil == Column("name")
|
||||
public func == (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return isEqual(lhs?.sqlExpression ?? DatabaseValue.null, rhs.sqlExpression)
|
||||
isEqual(lhs?.sqlExpression ?? DatabaseValue.null, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `=` SQL operator.
|
||||
@@ -88,7 +88,7 @@ public func == (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpress
|
||||
/// // name IS NULL
|
||||
/// nil == Column("name").collating(.nocase)
|
||||
public func == (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs == rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs == rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the boolean value of an expression.
|
||||
@@ -113,7 +113,7 @@ public func == (lhs: Bool, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
/// // email = login
|
||||
/// Column("email") == Column("login")
|
||||
public func == (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return isEqual(lhs.sqlExpression, rhs.sqlExpression)
|
||||
isEqual(lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<>` SQL operator.
|
||||
@@ -126,7 +126,7 @@ public func == (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
|
||||
/// // name IS NOT NULL
|
||||
/// Column("name") != nil
|
||||
public func != (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return isEqual(lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null).negated
|
||||
isEqual(lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null).negated
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<>` SQL operator.
|
||||
@@ -139,7 +139,7 @@ public func != (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpress
|
||||
/// // name IS NOT NULL
|
||||
/// Column("name").collating(.nocase) != nil
|
||||
public func != (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression != rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression != rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the boolean value of an expression.
|
||||
@@ -169,7 +169,7 @@ public func != (lhs: SQLSpecificExpressible, rhs: Bool) -> SQLExpression {
|
||||
/// // name IS NOT NULL
|
||||
/// nil != Column("name")
|
||||
public func != (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return isEqual(lhs?.sqlExpression ?? DatabaseValue.null, rhs.sqlExpression).negated
|
||||
isEqual(lhs?.sqlExpression ?? DatabaseValue.null, rhs.sqlExpression).negated
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<>` SQL operator.
|
||||
@@ -182,7 +182,7 @@ public func != (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpress
|
||||
/// // name IS NOT NULL
|
||||
/// nil != Column("name").collating(.nocase)
|
||||
public func != (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs != rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs != rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the boolean value of an expression.
|
||||
@@ -207,7 +207,7 @@ public func != (lhs: Bool, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
/// // email <> login
|
||||
/// Column("email") != Column("login")
|
||||
public func != (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return isEqual(lhs.sqlExpression, rhs.sqlExpression).negated
|
||||
isEqual(lhs.sqlExpression, rhs.sqlExpression).negated
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS` SQL operator.
|
||||
@@ -215,7 +215,7 @@ public func != (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
|
||||
/// // name IS 'Arthur'
|
||||
/// Column("name") === "Arthur"
|
||||
public func === (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionEqual(.is, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
SQLExpressionEqual(.is, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS` SQL operator.
|
||||
@@ -223,7 +223,7 @@ public func === (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpres
|
||||
/// // name IS 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) === "Arthur"
|
||||
public func === (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression === rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression === rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS` SQL operator.
|
||||
@@ -243,7 +243,7 @@ public func === (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpres
|
||||
/// // name IS 'Arthur' COLLATE NOCASE
|
||||
/// "Arthur" === Column("name").collating(.nocase)
|
||||
public func === (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs === rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs === rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS` SQL operator.
|
||||
@@ -251,7 +251,7 @@ public func === (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpress
|
||||
/// // email IS login
|
||||
/// Column("email") === Column("login")
|
||||
public func === (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionEqual(.is, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionEqual(.is, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
|
||||
@@ -259,7 +259,7 @@ public func === (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQ
|
||||
/// // name IS NOT 'Arthur'
|
||||
/// Column("name") !== "Arthur"
|
||||
public func !== (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs?.sqlExpression ?? DatabaseValue.null)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
|
||||
@@ -267,7 +267,7 @@ public func !== (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpres
|
||||
/// // name IS NOT 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) !== "Arthur"
|
||||
public func !== (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression !== rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression !== rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
|
||||
@@ -287,7 +287,7 @@ public func !== (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpres
|
||||
/// // name IS NOT 'Arthur' COLLATE NOCASE
|
||||
/// "Arthur" !== Column("name").collating(.nocase)
|
||||
public func !== (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs !== rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs !== rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
|
||||
@@ -295,7 +295,7 @@ public func !== (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpress
|
||||
/// // email IS NOT login
|
||||
/// Column("email") !== Column("login")
|
||||
public func !== (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionEqual(.isNot, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ extension SQLBinaryOperator {
|
||||
/// // score < 18
|
||||
/// Column("score") < 18
|
||||
public func < (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<` SQL operator.
|
||||
@@ -328,7 +328,7 @@ public func < (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // name < 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) < "Arthur"
|
||||
public func < (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression < rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression < rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<` SQL operator.
|
||||
@@ -336,7 +336,7 @@ public func < (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression
|
||||
/// // 18 < score
|
||||
/// 18 < Column("score")
|
||||
public func < (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<` SQL operator.
|
||||
@@ -344,7 +344,7 @@ public func < (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // 'Arthur' < name COLLATE NOCASE
|
||||
/// "Arthur" < Column("name").collating(.nocase)
|
||||
public func < (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs < rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs < rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<` SQL operator.
|
||||
@@ -352,7 +352,7 @@ public func < (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression
|
||||
/// // width < height
|
||||
/// Column("width") < Column("height")
|
||||
public func < (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<=` SQL operator.
|
||||
@@ -360,7 +360,7 @@ public func < (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLE
|
||||
/// // score <= 18
|
||||
/// Column("score") <= 18
|
||||
public func <= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<=` SQL operator.
|
||||
@@ -368,7 +368,7 @@ public func <= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
|
||||
/// // name <= 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) <= "Arthur"
|
||||
public func <= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression <= rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression <= rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<=` SQL operator.
|
||||
@@ -376,7 +376,7 @@ public func <= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 18 <= score
|
||||
/// 18 <= Column("score")
|
||||
public func <= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<=` SQL operator.
|
||||
@@ -384,7 +384,7 @@ public func <= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
|
||||
/// // 'Arthur' <= name COLLATE NOCASE
|
||||
/// "Arthur" <= Column("name").collating(.nocase)
|
||||
public func <= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs <= rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs <= rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `<=` SQL operator.
|
||||
@@ -392,7 +392,7 @@ public func <= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpressio
|
||||
/// // width <= height
|
||||
/// Column("width") <= Column("height")
|
||||
public func <= (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>` SQL operator.
|
||||
@@ -400,7 +400,7 @@ public func <= (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
|
||||
/// // score > 18
|
||||
/// Column("score") > 18
|
||||
public func > (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>` SQL operator.
|
||||
@@ -408,7 +408,7 @@ public func > (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // name > 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) > "Arthur"
|
||||
public func > (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression > rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression > rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>` SQL operator.
|
||||
@@ -416,7 +416,7 @@ public func > (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression
|
||||
/// // 18 > score
|
||||
/// 18 > Column("score")
|
||||
public func > (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>` SQL operator.
|
||||
@@ -424,7 +424,7 @@ public func > (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // 'Arthur' > name COLLATE NOCASE
|
||||
/// "Arthur" > Column("name").collating(.nocase)
|
||||
public func > (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs > rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs > rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>` SQL operator.
|
||||
@@ -432,7 +432,7 @@ public func > (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression
|
||||
/// // width > height
|
||||
/// Column("width") > Column("height")
|
||||
public func > (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>=` SQL operator.
|
||||
@@ -440,7 +440,7 @@ public func > (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLE
|
||||
/// // score >= 18
|
||||
/// Column("score") >= 18
|
||||
public func >= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>=` SQL operator.
|
||||
@@ -448,7 +448,7 @@ public func >= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
|
||||
/// // name >= 'Arthur' COLLATE NOCASE
|
||||
/// Column("name").collating(.nocase) >= "Arthur"
|
||||
public func >= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs.expression >= rhs, collationName: lhs.collationName)
|
||||
SQLExpressionCollate(lhs.expression >= rhs, collationName: lhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>=` SQL operator.
|
||||
@@ -456,7 +456,7 @@ public func >= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 18 >= score
|
||||
/// 18 >= Column("score")
|
||||
public func >= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>=` SQL operator.
|
||||
@@ -464,7 +464,7 @@ public func >= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
|
||||
/// // 'Arthur' >= name COLLATE NOCASE
|
||||
/// "Arthur" >= Column("name").collating(.nocase)
|
||||
public func >= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(lhs >= rhs.expression, collationName: rhs.collationName)
|
||||
SQLExpressionCollate(lhs >= rhs.expression, collationName: rhs.collationName)
|
||||
}
|
||||
|
||||
/// An SQL expression that compares two expressions with the `>=` SQL operator.
|
||||
@@ -472,7 +472,7 @@ public func >= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpressio
|
||||
/// // width >= height
|
||||
/// Column("width") >= Column("height")
|
||||
public func >= (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -484,7 +484,7 @@ extension Range where Bound: SQLExpressible {
|
||||
/// // email >= 'A' AND email < 'B'
|
||||
/// ("A"..<"B").contains(Column("email"))
|
||||
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
|
||||
return (element >= lowerBound) && (element < upperBound)
|
||||
(element >= lowerBound) && (element < upperBound)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the inclusion of an expression in a range.
|
||||
@@ -492,7 +492,7 @@ extension Range where Bound: SQLExpressible {
|
||||
/// // email >= 'A' COLLATE NOCASE AND email < 'B' COLLATE NOCASE
|
||||
/// ("A"..<"B").contains(Column("email").collating(.nocase))
|
||||
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
|
||||
return (element >= lowerBound) && (element < upperBound)
|
||||
(element >= lowerBound) && (element < upperBound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ extension ClosedRange where Bound: SQLExpressible {
|
||||
/// // email BETWEEN 'A' AND 'B'
|
||||
/// ("A"..."B").contains(Column("email"))
|
||||
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBetween(element.sqlExpression, lowerBound.sqlExpression, upperBound.sqlExpression)
|
||||
SQLExpressionBetween(element.sqlExpression, lowerBound.sqlExpression, upperBound.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the inclusion of an expression in a range.
|
||||
@@ -510,7 +510,7 @@ extension ClosedRange where Bound: SQLExpressible {
|
||||
/// // email BETWEEN 'A' AND 'B' COLLATE NOCASE
|
||||
/// ("A"..."B").contains(Column("email").collating(.nocase))
|
||||
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(contains(element.expression), collationName: element.collationName)
|
||||
SQLExpressionCollate(contains(element.expression), collationName: element.collationName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ extension CountableRange where Bound: SQLExpressible {
|
||||
/// // id BETWEEN 1 AND 9
|
||||
/// (1..<10).contains(Column("id"))
|
||||
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
|
||||
return (element >= lowerBound) && (element < upperBound)
|
||||
(element >= lowerBound) && (element < upperBound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ extension CountableClosedRange where Bound: SQLExpressible {
|
||||
/// // id BETWEEN 1 AND 10
|
||||
/// (1...10).contains(Column("id"))
|
||||
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBetween(element.sqlExpression, lowerBound.sqlExpression, upperBound.sqlExpression)
|
||||
SQLExpressionBetween(element.sqlExpression, lowerBound.sqlExpression, upperBound.sqlExpression)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,7 +541,7 @@ extension Sequence where Self.Iterator.Element: SQLExpressible {
|
||||
/// // id IN (1,2,3)
|
||||
/// [1, 2, 3].contains(Column("id"))
|
||||
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionsArray(self).contains(element.sqlExpression)
|
||||
SQLExpressionsArray(self).contains(element.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL expression that checks the inclusion of an expression in
|
||||
@@ -550,7 +550,7 @@ extension Sequence where Self.Iterator.Element: SQLExpressible {
|
||||
/// // name IN ('A', 'B') COLLATE NOCASE
|
||||
/// ["A", "B"].contains(Column("name").collating(.nocase))
|
||||
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
|
||||
return SQLExpressionCollate(contains(element.expression), collationName: element.collationName)
|
||||
SQLExpressionCollate(contains(element.expression), collationName: element.collationName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ extension SQLUnaryOperator {
|
||||
/// // width * 2
|
||||
/// Column("width") * 2
|
||||
public func * (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// An SQL arithmetic multiplication.
|
||||
@@ -607,7 +607,7 @@ public func * (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 2 * width
|
||||
/// 2 * Column("width")
|
||||
public func * (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// An SQL arithmetic multiplication.
|
||||
@@ -615,7 +615,7 @@ public func * (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // width * height
|
||||
/// Column("width") * Column("height")
|
||||
public func * (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.multiply, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// An SQL arithmetic division.
|
||||
@@ -623,7 +623,7 @@ public func * (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLE
|
||||
/// // width / 2
|
||||
/// Column("width") / 2
|
||||
public func / (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic division.
|
||||
@@ -631,7 +631,7 @@ public func / (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 2 / width
|
||||
/// 2 / Column("width")
|
||||
public func / (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic division.
|
||||
@@ -639,7 +639,7 @@ public func / (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // width / height
|
||||
/// Column("width") / Column("height")
|
||||
public func / (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.divide, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic addition.
|
||||
@@ -647,7 +647,7 @@ public func / (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLE
|
||||
/// // width + 2
|
||||
/// Column("width") + 2
|
||||
public func + (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// An SQL arithmetic addition.
|
||||
@@ -655,7 +655,7 @@ public func + (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 2 + width
|
||||
/// 2 + Column("width")
|
||||
public func + (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// An SQL arithmetic addition.
|
||||
@@ -663,7 +663,7 @@ public func + (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // width + height
|
||||
/// Column("width") + Column("height")
|
||||
public func + (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.add, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A negated SQL arithmetic expression.
|
||||
@@ -671,7 +671,7 @@ public func + (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLE
|
||||
/// // -width
|
||||
/// -Column("width")
|
||||
public prefix func - (value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionUnary(.minus, value.sqlExpression)
|
||||
SQLExpressionUnary(.minus, value.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic substraction.
|
||||
@@ -679,7 +679,7 @@ public prefix func - (value: SQLSpecificExpressible) -> SQLExpression {
|
||||
/// // width - 2
|
||||
/// Column("width") - 2
|
||||
public func - (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic substraction.
|
||||
@@ -687,7 +687,7 @@ public func - (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
|
||||
/// // 2 - width
|
||||
/// 2 - Column("width")
|
||||
public func - (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// An SQL arithmetic substraction.
|
||||
@@ -695,7 +695,7 @@ public func - (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
|
||||
/// // width - height
|
||||
/// Column("width") - Column("height")
|
||||
public func - (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
SQLExpressionBinary(.subtract, lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -730,7 +730,7 @@ extension SQLAssociativeBinaryOperator {
|
||||
/// // favorite AND 0
|
||||
/// Column("favorite") && false
|
||||
public func && (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A logical SQL expression with the `AND` SQL operator.
|
||||
@@ -738,7 +738,7 @@ public func && (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
|
||||
/// // 0 AND favorite
|
||||
/// false && Column("favorite")
|
||||
public func && (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A logical SQL expression with the `AND` SQL operator.
|
||||
@@ -746,7 +746,7 @@ public func && (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
|
||||
/// // email IS NOT NULL AND favorite
|
||||
/// Column("email") != nil && Column("favorite")
|
||||
public func && (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.and, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A logical SQL expression with the `OR` SQL operator.
|
||||
@@ -754,7 +754,7 @@ public func && (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
|
||||
/// // favorite OR 1
|
||||
/// Column("favorite") || true
|
||||
public func || (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A logical SQL expression with the `OR` SQL operator.
|
||||
@@ -762,7 +762,7 @@ public func || (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
|
||||
/// // 0 OR favorite
|
||||
/// true || Column("favorite")
|
||||
public func || (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A logical SQL expression with the `OR` SQL operator.
|
||||
@@ -770,7 +770,7 @@ public func || (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
|
||||
/// // email IS NULL OR hidden
|
||||
/// Column("email") == nil || Column("hidden")
|
||||
public func || (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
SQLExpressionBinaryReduce(.or, [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// A negated logical SQL expression with the `NOT` SQL operator.
|
||||
@@ -783,7 +783,7 @@ public func || (lhs: SQLSpecificExpressible, rhs: SQLSpecificExpressible) -> SQL
|
||||
/// // id NOT BETWEEN 1 AND 10
|
||||
/// !((1...10).contains(Column("id")))
|
||||
public prefix func ! (value: SQLSpecificExpressible) -> SQLExpression {
|
||||
return value.sqlExpression.negated
|
||||
value.sqlExpression.negated
|
||||
}
|
||||
|
||||
// MARK: - Like Operator
|
||||
@@ -801,7 +801,7 @@ extension SQLSpecificExpressible {
|
||||
/// // email LIKE '%@example.com"
|
||||
/// Column("email").like("%@example.com")
|
||||
public func like(_ pattern: SQLExpressible) -> SQLExpression {
|
||||
return SQLExpressionBinary(.like, self, pattern)
|
||||
SQLExpressionBinary(.like, self, pattern)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,83 +31,83 @@ struct SQLQuery {
|
||||
|
||||
extension SQLQuery: KeyPathRefining {
|
||||
func distinct() -> SQLQuery {
|
||||
return with(\.isDistinct, true)
|
||||
with(\.isDistinct, true)
|
||||
}
|
||||
|
||||
func expectingSingleResult() -> SQLQuery {
|
||||
return with(\.expectsSingleResult, true)
|
||||
with(\.expectsSingleResult, true)
|
||||
}
|
||||
|
||||
func limit(_ limit: Int, offset: Int? = nil) -> SQLQuery {
|
||||
return with(\.limit, SQLLimit(limit: limit, offset: offset))
|
||||
with(\.limit, SQLLimit(limit: limit, offset: offset))
|
||||
}
|
||||
|
||||
func qualified(with alias: TableAlias) -> SQLQuery {
|
||||
// We do not need to qualify group and having clauses. They will be
|
||||
// in SQLQueryGenerator.init()
|
||||
return map(\.relation, { $0.qualified(with: alias) })
|
||||
map(\.relation, { $0.qualified(with: alias) })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLQuery: SelectionRequest {
|
||||
func select(_ selection: [SQLSelectable]) -> SQLQuery {
|
||||
return map(\.relation, { $0.select(selection) })
|
||||
map(\.relation, { $0.select(selection) })
|
||||
}
|
||||
|
||||
func annotated(with selection: [SQLSelectable]) -> SQLQuery {
|
||||
return map(\.relation, { $0.annotated(with: selection) })
|
||||
map(\.relation, { $0.annotated(with: selection) })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLQuery: FilteredRequest {
|
||||
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLQuery {
|
||||
return map(\.relation, { $0.filter(predicate) })
|
||||
map(\.relation, { $0.filter(predicate) })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLQuery: OrderedRequest {
|
||||
func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLQuery {
|
||||
return map(\.relation, { $0.order(orderings) })
|
||||
map(\.relation, { $0.order(orderings) })
|
||||
}
|
||||
|
||||
func reversed() -> SQLQuery {
|
||||
return map(\.relation, { $0.reversed() })
|
||||
map(\.relation, { $0.reversed() })
|
||||
}
|
||||
|
||||
func unordered() -> SQLQuery {
|
||||
return map(\.relation, { $0.unordered() })
|
||||
map(\.relation, { $0.unordered() })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLQuery: AggregatingRequest {
|
||||
func group(_ expressions: @escaping (Database) throws -> [SQLExpressible]) -> SQLQuery {
|
||||
return with(\.groupPromise, DatabasePromise { db in try expressions(db).map(\.sqlExpression) })
|
||||
with(\.groupPromise, DatabasePromise { db in try expressions(db).map(\.sqlExpression) })
|
||||
}
|
||||
|
||||
func having(_ predicate: SQLExpressible) -> SQLQuery {
|
||||
return mapInto(\.havingExpressions, { $0.append(predicate.sqlExpression) })
|
||||
mapInto(\.havingExpressions, { $0.append(predicate.sqlExpression) })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLQuery: _JoinableRequest {
|
||||
func _including(all association: SQLAssociation) -> SQLQuery {
|
||||
return map(\.relation, { $0._including(all: association) })
|
||||
map(\.relation, { $0._including(all: association) })
|
||||
}
|
||||
|
||||
func _including(optional association: SQLAssociation) -> SQLQuery {
|
||||
return map(\.relation, { $0._including(optional: association) })
|
||||
map(\.relation, { $0._including(optional: association) })
|
||||
}
|
||||
|
||||
func _including(required association: SQLAssociation) -> SQLQuery {
|
||||
return map(\.relation, { $0._including(required: association) })
|
||||
map(\.relation, { $0._including(required: association) })
|
||||
}
|
||||
|
||||
func _joining(optional association: SQLAssociation) -> SQLQuery {
|
||||
return map(\.relation, { $0._joining(optional: association) })
|
||||
map(\.relation, { $0._joining(optional: association) })
|
||||
}
|
||||
|
||||
func _joining(required association: SQLAssociation) -> SQLQuery {
|
||||
return map(\.relation, { $0._joining(required: association) })
|
||||
map(\.relation, { $0._joining(required: association) })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ struct SQLRelation {
|
||||
var children: OrderedDictionary<String, Child>
|
||||
|
||||
var prefetchedAssociations: [SQLAssociation] {
|
||||
return children.flatMap { key, child -> [SQLAssociation] in
|
||||
children.flatMap { key, child -> [SQLAssociation] in
|
||||
switch child.kind {
|
||||
case .allPrefetched:
|
||||
return [child.makeAssociationForKey(key)]
|
||||
@@ -193,22 +193,21 @@ struct SQLRelation {
|
||||
|
||||
extension SQLRelation: KeyPathRefining {
|
||||
func select(_ selection: [SQLSelectable]) -> SQLRelation {
|
||||
return with(\.selection, selection)
|
||||
with(\.selection, selection)
|
||||
}
|
||||
|
||||
/// Removes all selections from chidren
|
||||
func selectOnly(_ selection: [SQLSelectable]) -> SQLRelation {
|
||||
return self
|
||||
.with(\.selection, selection)
|
||||
self.with(\.selection, selection)
|
||||
.map(\.children, { $0.mapValues { $0.map(\.relation, { $0.selectOnly([]) }) } })
|
||||
}
|
||||
|
||||
func annotated(with selection: [SQLSelectable]) -> SQLRelation {
|
||||
return mapInto(\.selection, { $0.append(contentsOf: selection) })
|
||||
mapInto(\.selection, { $0.append(contentsOf: selection) })
|
||||
}
|
||||
|
||||
func filter(_ predicate: @escaping (Database) throws -> SQLExpressible) -> SQLRelation {
|
||||
return map(\.filtersPromise, { filtersPromise in
|
||||
map(\.filtersPromise, { filtersPromise in
|
||||
filtersPromise.flatMap { filters in
|
||||
DatabasePromise { try filters + [predicate($0).sqlExpression] }
|
||||
}
|
||||
@@ -216,21 +215,20 @@ extension SQLRelation: KeyPathRefining {
|
||||
}
|
||||
|
||||
func order(_ orderings: @escaping (Database) throws -> [SQLOrderingTerm]) -> SQLRelation {
|
||||
return with(\.ordering, SQLRelation.Ordering(orderings: orderings))
|
||||
with(\.ordering, SQLRelation.Ordering(orderings: orderings))
|
||||
}
|
||||
|
||||
func reversed() -> SQLRelation {
|
||||
return map(\.ordering, \.reversed)
|
||||
map(\.ordering, \.reversed)
|
||||
}
|
||||
|
||||
func unordered() -> SQLRelation {
|
||||
return self
|
||||
.with(\.ordering, SQLRelation.Ordering())
|
||||
self.with(\.ordering, SQLRelation.Ordering())
|
||||
.map(\.children, { $0.mapValues { $0.map(\.relation, { $0.unordered() }) } })
|
||||
}
|
||||
|
||||
func qualified(with alias: TableAlias) -> SQLRelation {
|
||||
return map(\.source, { $0.qualified(with: alias) })
|
||||
map(\.source, { $0.qualified(with: alias) })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,33 +349,33 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
func removingChild(forKey key: String) -> SQLRelation {
|
||||
return mapInto(\.children, { $0.removeValue(forKey: key) })
|
||||
mapInto(\.children, { $0.removeValue(forKey: key) })
|
||||
}
|
||||
|
||||
func filteringChildren(_ included: (Child) throws -> Bool) rethrows -> SQLRelation {
|
||||
return try map(\.children, { try $0.filter { try included($1) } })
|
||||
try map(\.children, { try $0.filter { try included($1) } })
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLRelation: _JoinableRequest {
|
||||
func _including(all association: SQLAssociation) -> SQLRelation {
|
||||
return appendingChild(for: association, kind: .allPrefetched)
|
||||
appendingChild(for: association, kind: .allPrefetched)
|
||||
}
|
||||
|
||||
func _including(optional association: SQLAssociation) -> SQLRelation {
|
||||
return appendingChild(for: association, kind: .oneOptional)
|
||||
appendingChild(for: association, kind: .oneOptional)
|
||||
}
|
||||
|
||||
func _including(required association: SQLAssociation) -> SQLRelation {
|
||||
return appendingChild(for: association, kind: .oneRequired)
|
||||
appendingChild(for: association, kind: .oneRequired)
|
||||
}
|
||||
|
||||
func _joining(optional association: SQLAssociation) -> SQLRelation {
|
||||
return appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneOptional)
|
||||
appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneOptional)
|
||||
}
|
||||
|
||||
func _joining(required association: SQLAssociation) -> SQLRelation {
|
||||
return appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneRequired)
|
||||
appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneRequired)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,9 +441,7 @@ extension SQLRelation {
|
||||
private var elements: [Element] = []
|
||||
var isReversed: Bool
|
||||
|
||||
var isEmpty: Bool {
|
||||
return elements.isEmpty
|
||||
}
|
||||
var isEmpty: Bool { elements.isEmpty }
|
||||
|
||||
private init(elements: [Element], isReversed: Bool) {
|
||||
self.elements = elements
|
||||
@@ -465,19 +461,19 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
var reversed: Ordering {
|
||||
return Ordering(
|
||||
Ordering(
|
||||
elements: elements,
|
||||
isReversed: !isReversed)
|
||||
}
|
||||
|
||||
func qualified(with alias: TableAlias) -> Ordering {
|
||||
return Ordering(
|
||||
Ordering(
|
||||
elements: elements.map { $0.qualified(with: alias) },
|
||||
isReversed: isReversed)
|
||||
}
|
||||
|
||||
func appending(_ ordering: Ordering) -> Ordering {
|
||||
return Ordering(
|
||||
Ordering(
|
||||
elements: elements + [.ordering(ordering)],
|
||||
isReversed: isReversed)
|
||||
}
|
||||
@@ -543,7 +539,7 @@ struct SQLAssociationCondition: Equatable {
|
||||
var originIsLeft: Bool
|
||||
|
||||
var reversed: SQLAssociationCondition {
|
||||
return SQLAssociationCondition(
|
||||
SQLAssociationCondition(
|
||||
foreignKeyRequest: foreignKeyRequest,
|
||||
originIsLeft: !originIsLeft)
|
||||
}
|
||||
@@ -572,7 +568,7 @@ struct SQLAssociationCondition: Equatable {
|
||||
/// - Returns: An array of SQL expression that should be joined with
|
||||
/// the AND operator.
|
||||
func expressions(_ db: Database, leftAlias: TableAlias, rightAlias: TableAlias) throws -> [SQLExpression] {
|
||||
return try columnMappings(db).map {
|
||||
try columnMappings(db).map {
|
||||
QualifiedColumn($0.right, alias: rightAlias) == QualifiedColumn($0.left, alias: leftAlias)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ extension AllColumns: SQLSelectable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return "*"
|
||||
"*"
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func countedSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return "*"
|
||||
"*"
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -48,7 +48,7 @@ extension AllColumns: SQLSelectable {
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
/// :nodoc:
|
||||
public func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
|
||||
return QualifiedAllColumns(alias: alias)
|
||||
QualifiedAllColumns(alias: alias)
|
||||
}
|
||||
|
||||
/// [**Experimental**](http://github.com/groue/GRDB.swift#what-are-experimental-features)
|
||||
@@ -102,9 +102,7 @@ extension QualifiedAllColumns: SQLSelectable {
|
||||
return "*"
|
||||
}
|
||||
|
||||
func count(distinct: Bool) -> SQLCount? {
|
||||
return nil
|
||||
}
|
||||
func count(distinct: Bool) -> SQLCount? { nil }
|
||||
|
||||
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
|
||||
// Never requalify
|
||||
@@ -112,7 +110,7 @@ extension QualifiedAllColumns: SQLSelectable {
|
||||
}
|
||||
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
return try db.columns(in: alias.tableName).count
|
||||
try db.columns(in: alias.tableName).count
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,22 +126,20 @@ struct SQLAliasedExpression: SQLSelectable {
|
||||
}
|
||||
|
||||
func resultColumnSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return expression.resultColumnSQL(&context) + " AS " + name.quotedDatabaseIdentifier
|
||||
expression.resultColumnSQL(&context) + " AS " + name.quotedDatabaseIdentifier
|
||||
}
|
||||
|
||||
func countedSQL(_ context: inout SQLGenerationContext) -> String {
|
||||
return expression.countedSQL(&context)
|
||||
expression.countedSQL(&context)
|
||||
}
|
||||
|
||||
func count(distinct: Bool) -> SQLCount? {
|
||||
return expression.count(distinct: distinct)
|
||||
expression.count(distinct: distinct)
|
||||
}
|
||||
|
||||
func qualifiedSelectable(with alias: TableAlias) -> SQLSelectable {
|
||||
return SQLAliasedExpression(expression.qualifiedExpression(with: alias), name: name)
|
||||
SQLAliasedExpression(expression.qualifiedExpression(with: alias), name: name)
|
||||
}
|
||||
|
||||
func columnCount(_ db: Database) throws -> Int {
|
||||
return 1
|
||||
}
|
||||
func columnCount(_ db: Database) throws -> Int { 1 }
|
||||
}
|
||||
@@ -7,14 +7,14 @@ extension SQLSpecificExpressible {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var asc: SQLOrderingTerm {
|
||||
return SQLOrdering.asc(sqlExpression)
|
||||
SQLOrdering.asc(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns a value that can be used as an argument to QueryInterfaceRequest.order()
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var desc: SQLOrderingTerm {
|
||||
return SQLOrdering.desc(sqlExpression)
|
||||
SQLOrdering.desc(sqlExpression)
|
||||
}
|
||||
|
||||
#if GRDBCUSTOMSQLITE
|
||||
@@ -22,14 +22,14 @@ extension SQLSpecificExpressible {
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var ascNullsLast: SQLOrderingTerm {
|
||||
return SQLOrdering.ascNullsLast(sqlExpression)
|
||||
SQLOrdering.ascNullsLast(sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns a value that can be used as an argument to QueryInterfaceRequest.order()
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var descNullsFirst: SQLOrderingTerm {
|
||||
return SQLOrdering.descNullsFirst(sqlExpression)
|
||||
SQLOrdering.descNullsFirst(sqlExpression)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -50,7 +50,7 @@ extension SQLSpecificExpressible {
|
||||
/// let area: Int = row["area"]
|
||||
/// }
|
||||
public func forKey(_ key: String) -> SQLSelectable {
|
||||
return SQLAliasedExpression(sqlExpression, name: key)
|
||||
SQLAliasedExpression(sqlExpression, name: key)
|
||||
}
|
||||
|
||||
/// Give the expression the same SQL name as the coding key.
|
||||
@@ -72,7 +72,7 @@ extension SQLSpecificExpressible {
|
||||
/// // SELECT width, height, (width * height) AS area FROM shape
|
||||
/// let shapes: [Shape] = try Shape.fetchAll(db)
|
||||
public func forKey(_ key: CodingKey) -> SQLSelectable {
|
||||
return forKey(key.stringValue)
|
||||
forKey(key.stringValue)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ extension SQLSpecificExpressible {
|
||||
///
|
||||
/// Player.filter(Column("email").collating(.nocase) == "contact@example.com")
|
||||
public func collating(_ collation: Database.CollationName) -> SQLCollatedExpression {
|
||||
return SQLCollatedExpression(sqlExpression, collationName: collation)
|
||||
SQLCollatedExpression(sqlExpression, collationName: collation)
|
||||
}
|
||||
|
||||
/// Returns a collated expression.
|
||||
@@ -97,6 +97,6 @@ extension SQLSpecificExpressible {
|
||||
///
|
||||
/// Player.filter(Column("name").collating(.localizedStandardCompare) == "Hervé")
|
||||
public func collating(_ collation: DatabaseCollation) -> SQLCollatedExpression {
|
||||
return SQLCollatedExpression(sqlExpression, collationName: Database.CollationName(collation.name))
|
||||
SQLCollatedExpression(sqlExpression, collationName: Database.CollationName(collation.name))
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/// :nodoc:
|
||||
public struct SQLGenerationContext {
|
||||
var arguments: StatementArguments {
|
||||
return _arguments ?? StatementArguments()
|
||||
_arguments ?? StatementArguments()
|
||||
}
|
||||
private var _arguments: StatementArguments?
|
||||
private var resolvedNames: [TableAlias: String]
|
||||
@@ -32,7 +32,7 @@ public struct SQLGenerationContext {
|
||||
|
||||
/// Used for SQLQueryGenerator
|
||||
static func queryContext(aliases: [TableAlias]) -> SQLGenerationContext {
|
||||
return SQLGenerationContext(
|
||||
SQLGenerationContext(
|
||||
_arguments: [],
|
||||
resolvedNames: aliases.resolvedNames,
|
||||
qualifierNeeded: aliases.count > 1)
|
||||
@@ -70,7 +70,7 @@ public struct SQLGenerationContext {
|
||||
|
||||
/// WHERE <resolvedName> MATCH pattern
|
||||
func resolvedName(for alias: TableAlias) -> String {
|
||||
return resolvedNames[alias] ?? alias.identityName
|
||||
resolvedNames[alias] ?? alias.identityName
|
||||
}
|
||||
|
||||
/// FROM tableName <alias>
|
||||
@@ -149,12 +149,12 @@ public class TableAlias: Hashable {
|
||||
|
||||
// exposed to SQLGenerationContext
|
||||
fileprivate var identityName: String {
|
||||
return userName ?? tableName
|
||||
userName ?? tableName
|
||||
}
|
||||
|
||||
// exposed to SQLGenerationContext
|
||||
fileprivate var hasUserName: Bool {
|
||||
return userName != nil
|
||||
userName != nil
|
||||
}
|
||||
|
||||
var tableName: String {
|
||||
@@ -283,7 +283,7 @@ public class TableAlias: Hashable {
|
||||
|
||||
/// :nodoc:
|
||||
public static func == (lhs: TableAlias, rhs: TableAlias) -> Bool {
|
||||
return ObjectIdentifier(lhs.root) == ObjectIdentifier(rhs.root)
|
||||
ObjectIdentifier(lhs.root) == ObjectIdentifier(rhs.root)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ struct SQLQueryGenerator {
|
||||
}
|
||||
|
||||
func prepare(_ db: Database) throws -> (SelectStatement, RowAdapter?) {
|
||||
return try (makeSelectStatement(db), rowAdapter(db))
|
||||
try (makeSelectStatement(db), rowAdapter(db))
|
||||
}
|
||||
|
||||
private func optimizedDatabaseRegion(_ db: Database, _ databaseRegion: DatabaseRegion) throws -> DatabaseRegion {
|
||||
@@ -406,7 +406,7 @@ struct SQLQueryGenerator {
|
||||
/// let author: Author = row["author"]
|
||||
/// }
|
||||
private func rowAdapter(_ db: Database) throws -> RowAdapter? {
|
||||
return try relation.rowAdapter(db, fromIndex: 0)?.adapter
|
||||
try relation.rowAdapter(db, fromIndex: 0)?.adapter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,11 +421,11 @@ struct SQLQueryGenerator {
|
||||
/// • selection
|
||||
private struct SQLQualifiedRelation {
|
||||
/// The source alias
|
||||
var sourceAlias: TableAlias { return source.alias }
|
||||
var sourceAlias: TableAlias { source.alias }
|
||||
|
||||
/// All aliases, including aliases of joined relations
|
||||
var allAliases: [TableAlias] {
|
||||
return joins.reduce(into: source.allAliases) {
|
||||
joins.reduce(into: source.allAliases) {
|
||||
$0.append(contentsOf: $1.value.relation.allAliases)
|
||||
}
|
||||
}
|
||||
@@ -446,7 +446,7 @@ private struct SQLQualifiedRelation {
|
||||
/// |
|
||||
/// • selection
|
||||
var selection: [SQLSelectable] {
|
||||
return joins.reduce(into: sourceSelection) {
|
||||
joins.reduce(into: sourceSelection) {
|
||||
$0.append(contentsOf: $1.value.relation.selection)
|
||||
}
|
||||
}
|
||||
@@ -467,7 +467,7 @@ private struct SQLQualifiedRelation {
|
||||
/// |
|
||||
/// • ordering
|
||||
var ordering: SQLRelation.Ordering {
|
||||
return joins.reduce(sourceOrdering) {
|
||||
joins.reduce(sourceOrdering) {
|
||||
$0.appending($1.value.relation.ordering)
|
||||
}
|
||||
}
|
||||
@@ -574,8 +574,7 @@ private struct SQLQualifiedRelation {
|
||||
|
||||
/// Removes all selections from joins
|
||||
func selectOnly(_ selection: [SQLSelectable]) -> SQLQualifiedRelation {
|
||||
return self
|
||||
.with(\.sourceSelection, selection.map { $0.qualifiedSelectable(with: sourceAlias) })
|
||||
self.with(\.sourceSelection, selection.map { $0.qualifiedSelectable(with: sourceAlias) })
|
||||
.map(\.joins, { $0.mapValues { $0.selectOnly([]) } })
|
||||
}
|
||||
}
|
||||
@@ -641,12 +640,12 @@ private struct SQLQualifiedJoin {
|
||||
let relation: SQLQualifiedRelation
|
||||
|
||||
func sql(_ db: Database, _ context: inout SQLGenerationContext, leftAlias: TableAlias) throws -> String {
|
||||
return try sql(db, &context, leftAlias: leftAlias, allowingInnerJoin: true)
|
||||
try sql(db, &context, leftAlias: leftAlias, allowingInnerJoin: true)
|
||||
}
|
||||
|
||||
/// Removes all selections from joins
|
||||
func selectOnly(_ selection: [SQLSelectable]) -> SQLQualifiedJoin {
|
||||
return SQLQualifiedJoin(
|
||||
SQLQualifiedJoin(
|
||||
kind: kind,
|
||||
condition: condition,
|
||||
relation: relation.selectOnly(selection))
|
||||
|
||||
@@ -553,7 +553,7 @@ extension TableRecord {
|
||||
/// // FROM player LEFT JOIN book ...
|
||||
/// var request = Player.annotated(with: Player.books.count)
|
||||
public static func annotated(with aggregates: AssociationAggregate<Self>...) -> QueryInterfaceRequest<Self> {
|
||||
return all().annotated(with: aggregates)
|
||||
all().annotated(with: aggregates)
|
||||
}
|
||||
|
||||
/// Creates a request with *aggregates* appended to the selection.
|
||||
@@ -562,7 +562,7 @@ extension TableRecord {
|
||||
/// // FROM player LEFT JOIN book ...
|
||||
/// var request = Player.annotated(with: [Player.books.count])
|
||||
public static func annotated(with aggregates: [AssociationAggregate<Self>]) -> QueryInterfaceRequest<Self> {
|
||||
return all().annotated(with: aggregates)
|
||||
all().annotated(with: aggregates)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided aggregate *predicate*.
|
||||
@@ -577,6 +577,6 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func having(_ predicate: AssociationAggregate<Self>) -> QueryInterfaceRequest<Self> {
|
||||
return all().having(predicate)
|
||||
all().having(predicate)
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ extension TableRecord {
|
||||
|
||||
/// Creates a request which fetches no record.
|
||||
public static func none() -> QueryInterfaceRequest<Self> {
|
||||
return all().none() // don't laugh
|
||||
all().none() // don't laugh
|
||||
}
|
||||
|
||||
/// Creates a request which selects *selection*.
|
||||
@@ -27,7 +27,7 @@ extension TableRecord {
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(Column("id"), Column("email"))
|
||||
public static func select(_ selection: SQLSelectable...) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(selection)
|
||||
all().select(selection)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *selection*.
|
||||
@@ -35,7 +35,7 @@ extension TableRecord {
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select([Column("id"), Column("email")])
|
||||
public static func select(_ selection: [SQLSelectable]) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(selection)
|
||||
all().select(selection)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *sql*.
|
||||
@@ -55,7 +55,7 @@ extension TableRecord {
|
||||
/// // SELECT id, email FROM player
|
||||
/// let request = Player.select(literal: SQLLiteral(sql: "id, email"))
|
||||
public static func select(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(literal: sqlLiteral)
|
||||
all().select(literal: sqlLiteral)
|
||||
}
|
||||
|
||||
/// Creates a request which selects *selection*, and fetches values of
|
||||
@@ -130,7 +130,7 @@ extension TableRecord {
|
||||
/// .select([Column("id"), Column("email")])
|
||||
/// .annotated(with: [Column("name")])
|
||||
public static func annotated(with selection: [SQLSelectable]) -> QueryInterfaceRequest<Self> {
|
||||
return all().annotated(with: selection)
|
||||
all().annotated(with: selection)
|
||||
}
|
||||
|
||||
/// Creates a request which appends *selection*.
|
||||
@@ -140,7 +140,7 @@ extension TableRecord {
|
||||
/// .select([Column("id"), Column("email")])
|
||||
/// .annotated(with: Column("name"))
|
||||
public static func annotated(with selection: SQLSelectable...) -> QueryInterfaceRequest<Self> {
|
||||
return all().annotated(with: selection)
|
||||
all().annotated(with: selection)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
@@ -152,7 +152,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(_ predicate: SQLExpressible) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(predicate)
|
||||
all().filter(predicate)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided primary key *predicate*.
|
||||
@@ -197,7 +197,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(key: [String: DatabaseValueConvertible?]?) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(key: key)
|
||||
all().filter(key: key)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided primary key *predicate*.
|
||||
@@ -212,7 +212,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func filter(keys: [[String: DatabaseValueConvertible?]]) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(keys: keys)
|
||||
all().filter(keys: keys)
|
||||
}
|
||||
|
||||
/// Creates a request with the provided *predicate*.
|
||||
@@ -259,7 +259,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func order(_ orderings: SQLOrderingTerm...) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(orderings)
|
||||
all().order(orderings)
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to the
|
||||
@@ -272,7 +272,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func order(_ orderings: [SQLOrderingTerm]) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(orderings)
|
||||
all().order(orderings)
|
||||
}
|
||||
|
||||
/// Creates a request sorted by primary key.
|
||||
@@ -287,7 +287,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func orderByPrimaryKey() -> QueryInterfaceRequest<Self> {
|
||||
return all().orderByPrimaryKey()
|
||||
all().orderByPrimaryKey()
|
||||
}
|
||||
|
||||
/// Creates a request sorted according to *sql*.
|
||||
@@ -321,7 +321,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func order(literal sqlLiteral: SQLLiteral) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(literal: sqlLiteral)
|
||||
all().order(literal: sqlLiteral)
|
||||
}
|
||||
|
||||
/// Creates a request which fetches *limit* rows, starting at
|
||||
@@ -334,7 +334,7 @@ extension TableRecord {
|
||||
/// all requests by the `TableRecord.databaseSelection` property, or
|
||||
/// for individual requests with the `TableRecord.select` method.
|
||||
public static func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<Self> {
|
||||
return all().limit(limit, offset: offset)
|
||||
all().limit(limit, offset: offset)
|
||||
}
|
||||
|
||||
/// Creates a request that allows you to define expressions that target
|
||||
@@ -354,6 +354,6 @@ extension TableRecord {
|
||||
/// .aliased(playerAlias)
|
||||
/// .including(required: Player.team.filter(Column("avgScore") < playerAlias[Column("score")])
|
||||
public static func aliased(_ alias: TableAlias) -> QueryInterfaceRequest<Self> {
|
||||
return all().aliased(alias)
|
||||
all().aliased(alias)
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,10 @@ extension EncodableRecord where Self: Encodable {
|
||||
|
||||
/// The encoder that encodes a record into GRDB's PersistenceContainer
|
||||
private class RecordEncoder<Record: EncodableRecord>: Encoder {
|
||||
var codingPath: [CodingKey] { return [] }
|
||||
var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo }
|
||||
var codingPath: [CodingKey] { [] }
|
||||
var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo }
|
||||
private var _persistenceContainer: PersistenceContainer
|
||||
var persistenceContainer: PersistenceContainer { return _persistenceContainer }
|
||||
var persistenceContainer: PersistenceContainer { _persistenceContainer }
|
||||
|
||||
init(persistenceContainer: PersistenceContainer) {
|
||||
_persistenceContainer = persistenceContainer
|
||||
@@ -47,13 +47,13 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
|
||||
|
||||
private struct KeyedContainer<Key: CodingKey>: KeyedEncodingContainerProtocol {
|
||||
var recordEncoder: RecordEncoder
|
||||
var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo }
|
||||
|
||||
init(recordEncoder: RecordEncoder) {
|
||||
self.recordEncoder = recordEncoder
|
||||
}
|
||||
|
||||
var codingPath: [CodingKey] { return [] }
|
||||
var codingPath: [CodingKey] { [] }
|
||||
|
||||
// swiftlint:disable comma
|
||||
func encode(_ value: Bool, forKey key: Key) throws { recordEncoder.persist(value, forKey: key) }
|
||||
@@ -174,8 +174,8 @@ private class RecordEncoder<Record: EncodableRecord>: Encoder {
|
||||
private class ColumnEncoder<Record: EncodableRecord>: Encoder {
|
||||
var recordEncoder: RecordEncoder<Record>
|
||||
var key: CodingKey
|
||||
var codingPath: [CodingKey] { return [key] }
|
||||
var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo }
|
||||
var codingPath: [CodingKey] { [key] }
|
||||
var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo }
|
||||
var requiresJSON = false
|
||||
|
||||
init(recordEncoder: RecordEncoder<Record>, key: CodingKey) {
|
||||
@@ -200,9 +200,7 @@ private class ColumnEncoder<Record: EncodableRecord>: Encoder {
|
||||
return JSONRequiredEncoder<Record>(codingPath: codingPath)
|
||||
}
|
||||
|
||||
func singleValueContainer() -> SingleValueEncodingContainer {
|
||||
return self
|
||||
}
|
||||
func singleValueContainer() -> SingleValueEncodingContainer { self }
|
||||
}
|
||||
|
||||
extension ColumnEncoder: SingleValueEncodingContainer {
|
||||
@@ -236,7 +234,7 @@ private struct JSONRequiredError: Error { }
|
||||
/// The encoder that always ends up with a JSONRequiredError
|
||||
private struct JSONRequiredEncoder<Record: EncodableRecord>: Encoder {
|
||||
var codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo }
|
||||
|
||||
init(codingPath: [CodingKey]) {
|
||||
self.codingPath = codingPath
|
||||
@@ -247,17 +245,13 @@ private struct JSONRequiredEncoder<Record: EncodableRecord>: Encoder {
|
||||
return KeyedEncodingContainer(container)
|
||||
}
|
||||
|
||||
func unkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
return self
|
||||
}
|
||||
func unkeyedContainer() -> UnkeyedEncodingContainer { self }
|
||||
|
||||
func singleValueContainer() -> SingleValueEncodingContainer {
|
||||
return self
|
||||
}
|
||||
func singleValueContainer() -> SingleValueEncodingContainer { self }
|
||||
|
||||
struct KeyedContainer<KeyType: CodingKey>: KeyedEncodingContainerProtocol {
|
||||
var codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any] { return Record.databaseEncodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { Record.databaseEncodingUserInfo }
|
||||
|
||||
func encodeNil(forKey key: KeyType) throws { throw JSONRequiredError() }
|
||||
func encode(_ value: Bool, forKey key: KeyType) throws { throw JSONRequiredError() }
|
||||
@@ -287,15 +281,15 @@ private struct JSONRequiredEncoder<Record: EncodableRecord>: Encoder {
|
||||
}
|
||||
|
||||
func nestedUnkeyedContainer(forKey key: KeyType) -> UnkeyedEncodingContainer {
|
||||
return JSONRequiredEncoder(codingPath: codingPath)
|
||||
JSONRequiredEncoder(codingPath: codingPath)
|
||||
}
|
||||
|
||||
func superEncoder() -> Encoder {
|
||||
return JSONRequiredEncoder(codingPath: codingPath)
|
||||
JSONRequiredEncoder(codingPath: codingPath)
|
||||
}
|
||||
|
||||
func superEncoder(forKey key: KeyType) -> Encoder {
|
||||
return JSONRequiredEncoder(codingPath: codingPath)
|
||||
JSONRequiredEncoder(codingPath: codingPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,7 +314,7 @@ extension JSONRequiredEncoder: SingleValueEncodingContainer {
|
||||
}
|
||||
|
||||
extension JSONRequiredEncoder: UnkeyedEncodingContainer {
|
||||
var count: Int { return 0 }
|
||||
var count: Int { 0 }
|
||||
|
||||
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type)
|
||||
-> KeyedEncodingContainer<NestedKey>
|
||||
@@ -330,13 +324,9 @@ extension JSONRequiredEncoder: UnkeyedEncodingContainer {
|
||||
return KeyedEncodingContainer(container)
|
||||
}
|
||||
|
||||
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer {
|
||||
return self
|
||||
}
|
||||
mutating func nestedUnkeyedContainer() -> UnkeyedEncodingContainer { self }
|
||||
|
||||
mutating func superEncoder() -> Encoder {
|
||||
return self
|
||||
}
|
||||
mutating func superEncoder() -> Encoder { self }
|
||||
}
|
||||
|
||||
@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)
|
||||
|
||||
@@ -121,7 +121,7 @@ public protocol EncodableRecord {
|
||||
|
||||
extension EncodableRecord {
|
||||
public static var databaseEncodingUserInfo: [CodingUserInfoKey: Any] {
|
||||
return [:]
|
||||
[:]
|
||||
}
|
||||
|
||||
public static func databaseJSONEncoder(for column: String) -> JSONEncoder {
|
||||
@@ -137,18 +137,18 @@ extension EncodableRecord {
|
||||
}
|
||||
|
||||
public static var databaseDateEncodingStrategy: DatabaseDateEncodingStrategy {
|
||||
return .deferredToDate
|
||||
.deferredToDate
|
||||
}
|
||||
|
||||
public static var databaseUUIDEncodingStrategy: DatabaseUUIDEncodingStrategy {
|
||||
return .deferredToUUID
|
||||
.deferredToUUID
|
||||
}
|
||||
}
|
||||
|
||||
extension EncodableRecord {
|
||||
/// A dictionary whose keys are the columns encoded in the `encode(to:)` method.
|
||||
public var databaseDictionary: [String: DatabaseValue] {
|
||||
return Dictionary(PersistenceContainer(self).storage).mapValues { $0?.databaseValue ?? .null }
|
||||
Dictionary(PersistenceContainer(self).storage).mapValues { $0?.databaseValue ?? .null }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ extension EncodableRecord {
|
||||
/// Returns a boolean indicating whether this record and the other record
|
||||
/// have the same database representation.
|
||||
public func databaseEquals(_ record: Self) -> Bool {
|
||||
return PersistenceContainer(self).changesIterator(from: PersistenceContainer(record)).next() == nil
|
||||
PersistenceContainer(self).changesIterator(from: PersistenceContainer(record)).next() == nil
|
||||
}
|
||||
|
||||
/// A dictionary of values changed from the other record.
|
||||
@@ -203,7 +203,7 @@ public struct PersistenceContainer {
|
||||
/// is considered undefined behavior.
|
||||
@inlinable
|
||||
public subscript(_ column: String) -> DatabaseValueConvertible? {
|
||||
get { return storage[column] ?? nil }
|
||||
get { storage[column] ?? nil }
|
||||
set { storage.updateValue(newValue, forKey: column) }
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ public struct PersistenceContainer {
|
||||
/// is considered undefined behavior.
|
||||
@inlinable
|
||||
public subscript<Column: ColumnExpression>(_ column: Column) -> DatabaseValueConvertible? {
|
||||
get { return self[column.name] }
|
||||
get { self[column.name] }
|
||||
set { self[column.name] = newValue }
|
||||
}
|
||||
|
||||
@@ -233,14 +233,10 @@ public struct PersistenceContainer {
|
||||
}
|
||||
|
||||
/// Columns stored in the container, ordered like values.
|
||||
var columns: [String] {
|
||||
return Array(storage.keys)
|
||||
}
|
||||
var columns: [String] { Array(storage.keys) }
|
||||
|
||||
/// Values stored in the container, ordered like columns.
|
||||
var values: [DatabaseValueConvertible?] {
|
||||
return Array(storage.values)
|
||||
}
|
||||
var values: [DatabaseValueConvertible?] { Array(storage.values) }
|
||||
|
||||
/// Accesses the value associated with the given column, in a
|
||||
/// case-insensitive fashion.
|
||||
@@ -281,13 +277,11 @@ public struct PersistenceContainer {
|
||||
return nil
|
||||
}
|
||||
|
||||
var isEmpty: Bool {
|
||||
return storage.isEmpty
|
||||
}
|
||||
var isEmpty: Bool { storage.isEmpty }
|
||||
|
||||
/// An iterator over the (column, value) pairs
|
||||
func makeIterator() -> IndexingIterator<OrderedDictionary<String, DatabaseValueConvertible?>> {
|
||||
return storage.makeIterator()
|
||||
storage.makeIterator()
|
||||
}
|
||||
|
||||
func changesIterator(from container: PersistenceContainer) -> AnyIterator<(String, DatabaseValue)> {
|
||||
|
||||
@@ -32,10 +32,10 @@ class RowDecoder {
|
||||
private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
var row: Row
|
||||
var codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
|
||||
return KeyedDecodingContainer(KeyedContainer<Key>(decoder: self))
|
||||
KeyedDecodingContainer(KeyedContainer<Key>(decoder: self))
|
||||
}
|
||||
|
||||
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
|
||||
@@ -73,7 +73,7 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
|
||||
class KeyedContainer<Key: CodingKey>: KeyedDecodingContainerProtocol {
|
||||
let decoder: _RowDecoder
|
||||
var codingPath: [CodingKey] { return decoder.codingPath }
|
||||
var codingPath: [CodingKey] { decoder.codingPath }
|
||||
var decodedRootKey: CodingKey?
|
||||
|
||||
init(decoder: _RowDecoder) {
|
||||
@@ -99,20 +99,20 @@ private struct _RowDecoder<R: FetchableRecord>: Decoder {
|
||||
}
|
||||
|
||||
// swiftlint:disable comma
|
||||
func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int.Type, forKey key: Key) throws -> Int { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int8.Type, forKey key: Key) throws -> Int8 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int16.Type, forKey key: Key) throws -> Int16 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int32.Type, forKey key: Key) throws -> Int32 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int64.Type, forKey key: Key) throws -> Int64 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt.Type, forKey key: Key) throws -> UInt { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt8.Type, forKey key: Key) throws -> UInt8 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt16.Type, forKey key: Key) throws -> UInt16 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt32.Type, forKey key: Key) throws -> UInt32 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt64.Type, forKey key: Key) throws -> UInt64 { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Float.Type, forKey key: Key) throws -> Float { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Double.Type, forKey key: Key) throws -> Double { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: String.Type, forKey key: Key) throws -> String { return decoder.row[key.stringValue] }
|
||||
func decode(_ type: Bool.Type, forKey key: Key) throws -> Bool { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int.Type, forKey key: Key) throws -> Int { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int8.Type, forKey key: Key) throws -> Int8 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int16.Type, forKey key: Key) throws -> Int16 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int32.Type, forKey key: Key) throws -> Int32 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Int64.Type, forKey key: Key) throws -> Int64 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt.Type, forKey key: Key) throws -> UInt { decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt8.Type, forKey key: Key) throws -> UInt8 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt16.Type, forKey key: Key) throws -> UInt16 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt32.Type, forKey key: Key) throws -> UInt32 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: UInt64.Type, forKey key: Key) throws -> UInt64 { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Float.Type, forKey key: Key) throws -> Float { decoder.row[key.stringValue] }
|
||||
func decode(_ type: Double.Type, forKey key: Key) throws -> Double { decoder.row[key.stringValue] }
|
||||
func decode(_ type: String.Type, forKey key: Key) throws -> String { decoder.row[key.stringValue] }
|
||||
// swiftlint:enable comma
|
||||
|
||||
func decodeIfPresent<T>(_ type: T.Type, forKey key: Key) throws -> T? where T: Decodable {
|
||||
@@ -303,7 +303,7 @@ private struct PrefetchedRowsDecoder<R: FetchableRecord>: Decoder {
|
||||
var rows: [Row]
|
||||
var codingPath: [CodingKey]
|
||||
var currentIndex: Int
|
||||
var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
|
||||
|
||||
init(rows: [Row], codingPath: [CodingKey]) {
|
||||
self.rows = rows
|
||||
@@ -315,9 +315,7 @@ private struct PrefetchedRowsDecoder<R: FetchableRecord>: Decoder {
|
||||
fatalError("keyed decoding from prefetched rows is not supported")
|
||||
}
|
||||
|
||||
func unkeyedContainer() throws -> UnkeyedDecodingContainer {
|
||||
return self
|
||||
}
|
||||
func unkeyedContainer() throws -> UnkeyedDecodingContainer { self }
|
||||
|
||||
func singleValueContainer() throws -> SingleValueDecodingContainer {
|
||||
fatalError("single value decoding from prefetched rows is not supported")
|
||||
@@ -325,17 +323,11 @@ private struct PrefetchedRowsDecoder<R: FetchableRecord>: Decoder {
|
||||
}
|
||||
|
||||
extension PrefetchedRowsDecoder: UnkeyedDecodingContainer {
|
||||
var count: Int? {
|
||||
return rows.count
|
||||
}
|
||||
var count: Int? { rows.count }
|
||||
|
||||
var isAtEnd: Bool {
|
||||
return currentIndex >= rows.count
|
||||
}
|
||||
var isAtEnd: Bool { currentIndex >= rows.count }
|
||||
|
||||
mutating func decodeNil() throws -> Bool {
|
||||
return false
|
||||
}
|
||||
mutating func decodeNil() throws -> Bool { false }
|
||||
|
||||
mutating func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
|
||||
defer { currentIndex += 1 }
|
||||
@@ -366,7 +358,7 @@ private struct ColumnDecoder<R: FetchableRecord>: Decoder {
|
||||
var row: Row
|
||||
var columnIndex: Int
|
||||
var codingPath: [CodingKey]
|
||||
var userInfo: [CodingUserInfoKey: Any] { return R.databaseDecodingUserInfo }
|
||||
var userInfo: [CodingUserInfoKey: Any] { R.databaseDecodingUserInfo }
|
||||
|
||||
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> {
|
||||
// We need to switch to JSON decoding
|
||||
@@ -378,30 +370,28 @@ private struct ColumnDecoder<R: FetchableRecord>: Decoder {
|
||||
throw JSONRequiredError()
|
||||
}
|
||||
|
||||
func singleValueContainer() throws -> SingleValueDecodingContainer {
|
||||
return self
|
||||
}
|
||||
func singleValueContainer() throws -> SingleValueDecodingContainer { self }
|
||||
}
|
||||
|
||||
extension ColumnDecoder: SingleValueDecodingContainer {
|
||||
func decodeNil() -> Bool {
|
||||
return row.hasNull(atIndex: columnIndex)
|
||||
row.hasNull(atIndex: columnIndex)
|
||||
}
|
||||
|
||||
func decode(_ type: Bool.Type ) throws -> Bool { return row[columnIndex] }
|
||||
func decode(_ type: Int.Type ) throws -> Int { return row[columnIndex] }
|
||||
func decode(_ type: Int8.Type ) throws -> Int8 { return row[columnIndex] }
|
||||
func decode(_ type: Int16.Type ) throws -> Int16 { return row[columnIndex] }
|
||||
func decode(_ type: Int32.Type ) throws -> Int32 { return row[columnIndex] }
|
||||
func decode(_ type: Int64.Type ) throws -> Int64 { return row[columnIndex] }
|
||||
func decode(_ type: UInt.Type ) throws -> UInt { return row[columnIndex] }
|
||||
func decode(_ type: UInt8.Type ) throws -> UInt8 { return row[columnIndex] }
|
||||
func decode(_ type: UInt16.Type) throws -> UInt16 { return row[columnIndex] }
|
||||
func decode(_ type: UInt32.Type) throws -> UInt32 { return row[columnIndex] }
|
||||
func decode(_ type: UInt64.Type) throws -> UInt64 { return row[columnIndex] }
|
||||
func decode(_ type: Float.Type ) throws -> Float { return row[columnIndex] }
|
||||
func decode(_ type: Double.Type) throws -> Double { return row[columnIndex] }
|
||||
func decode(_ type: String.Type) throws -> String { return row[columnIndex] }
|
||||
func decode(_ type: Bool.Type ) throws -> Bool { row[columnIndex] }
|
||||
func decode(_ type: Int.Type ) throws -> Int { row[columnIndex] }
|
||||
func decode(_ type: Int8.Type ) throws -> Int8 { row[columnIndex] }
|
||||
func decode(_ type: Int16.Type ) throws -> Int16 { row[columnIndex] }
|
||||
func decode(_ type: Int32.Type ) throws -> Int32 { row[columnIndex] }
|
||||
func decode(_ type: Int64.Type ) throws -> Int64 { row[columnIndex] }
|
||||
func decode(_ type: UInt.Type ) throws -> UInt { row[columnIndex] }
|
||||
func decode(_ type: UInt8.Type ) throws -> UInt8 { row[columnIndex] }
|
||||
func decode(_ type: UInt16.Type) throws -> UInt16 { row[columnIndex] }
|
||||
func decode(_ type: UInt32.Type) throws -> UInt32 { row[columnIndex] }
|
||||
func decode(_ type: UInt64.Type) throws -> UInt64 { row[columnIndex] }
|
||||
func decode(_ type: Float.Type ) throws -> Float { row[columnIndex] }
|
||||
func decode(_ type: Double.Type) throws -> Double { row[columnIndex] }
|
||||
func decode(_ type: String.Type) throws -> String { row[columnIndex] }
|
||||
|
||||
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
|
||||
// Prefer DatabaseValueConvertible decoding over Decodable.
|
||||
|
||||
@@ -25,7 +25,7 @@ extension FetchableRecord where Self: TableRecord {
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchCursor(_ db: Database) throws -> RecordCursor<Self> {
|
||||
return try all().fetchCursor(db)
|
||||
try all().fetchCursor(db)
|
||||
}
|
||||
|
||||
/// An array of all records fetched from the database.
|
||||
@@ -40,7 +40,7 @@ extension FetchableRecord where Self: TableRecord {
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchAll(_ db: Database) throws -> [Self] {
|
||||
return try all().fetchAll(db)
|
||||
try all().fetchAll(db)
|
||||
}
|
||||
|
||||
/// The first found record.
|
||||
@@ -55,7 +55,7 @@ extension FetchableRecord where Self: TableRecord {
|
||||
/// - parameter db: A database connection.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public static func fetchOne(_ db: Database) throws -> Self? {
|
||||
return try all().fetchOne(db)
|
||||
try all().fetchOne(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public protocol FetchableRecord {
|
||||
|
||||
extension FetchableRecord {
|
||||
public static var databaseDecodingUserInfo: [CodingUserInfoKey: Any] {
|
||||
return [:]
|
||||
[:]
|
||||
}
|
||||
|
||||
/// Returns a JSONDecoder with the following properties:
|
||||
@@ -133,7 +133,7 @@ extension FetchableRecord {
|
||||
}
|
||||
|
||||
public static var databaseDateDecodingStrategy: DatabaseDateDecodingStrategy {
|
||||
return .deferredToDate
|
||||
.deferredToDate
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ extension FetchRequest where RowDecoder: FetchableRecord {
|
||||
/// - returns: A cursor over fetched records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchCursor(_ db: Database) throws -> RecordCursor<RowDecoder> {
|
||||
return try RowDecoder.fetchCursor(db, self)
|
||||
try RowDecoder.fetchCursor(db, self)
|
||||
}
|
||||
|
||||
/// An array of fetched records.
|
||||
@@ -394,7 +394,7 @@ extension FetchRequest where RowDecoder: FetchableRecord {
|
||||
/// - returns: An array of records.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchAll(_ db: Database) throws -> [RowDecoder] {
|
||||
return try RowDecoder.fetchAll(db, self)
|
||||
try RowDecoder.fetchAll(db, self)
|
||||
}
|
||||
|
||||
/// The first fetched record.
|
||||
@@ -406,7 +406,7 @@ extension FetchRequest where RowDecoder: FetchableRecord {
|
||||
/// - returns: An optional record.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func fetchOne(_ db: Database) throws -> RowDecoder? {
|
||||
return try RowDecoder.fetchOne(db, self)
|
||||
try RowDecoder.fetchOne(db, self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -541,7 +541,7 @@ private final class FetchedRecordsObserver<Record: FetchableRecord>: Transaction
|
||||
}
|
||||
|
||||
func observes(eventsOfKind eventKind: DatabaseEventKind) -> Bool {
|
||||
return region.isModified(byEventsOfKind: eventKind)
|
||||
region.isModified(byEventsOfKind: eventKind)
|
||||
}
|
||||
|
||||
/// Part of the TransactionObserverType protocol
|
||||
@@ -1076,6 +1076,6 @@ private final class Item<T: FetchableRecord>: FetchableRecord, Equatable {
|
||||
}
|
||||
|
||||
static func ==<T> (lhs: Item<T>, rhs: Item<T>) -> Bool {
|
||||
return lhs.row == rhs.row
|
||||
lhs.row == rhs.row
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ extension MutablePersistableRecord {
|
||||
/// The default value specifies ABORT policy for both insertions and
|
||||
/// updates, which has GRDB generate regular INSERT and UPDATE queries.
|
||||
public static var persistenceConflictPolicy: PersistenceConflictPolicy {
|
||||
return PersistenceConflictPolicy(insert: .abort, update: .abort)
|
||||
PersistenceConflictPolicy(insert: .abort, update: .abort)
|
||||
}
|
||||
|
||||
/// Notifies the record that it was succesfully inserted.
|
||||
@@ -276,7 +276,7 @@ extension MutablePersistableRecord {
|
||||
/// - SeeAlso: updateChanges(_:with:)
|
||||
@discardableResult
|
||||
public func updateChanges<Record: MutablePersistableRecord>(_ db: Database, from record: Record) throws -> Bool {
|
||||
return try updateChanges(db, from: PersistenceContainer(db, record))
|
||||
try updateChanges(db, from: PersistenceContainer(db, record))
|
||||
}
|
||||
|
||||
/// Mutates the record according to the provided closure, and then, if the
|
||||
@@ -322,7 +322,7 @@ extension MutablePersistableRecord {
|
||||
/// The default implementation for delete() invokes performDelete().
|
||||
@discardableResult
|
||||
public func delete(_ db: Database) throws -> Bool {
|
||||
return try performDelete(db)
|
||||
try performDelete(db)
|
||||
}
|
||||
|
||||
/// Returns true if and only if the primary key matches a row in
|
||||
@@ -330,7 +330,7 @@ extension MutablePersistableRecord {
|
||||
///
|
||||
/// The default implementation for exists() invokes performExists().
|
||||
public func exists(_ db: Database) throws -> Bool {
|
||||
return try performExists(db)
|
||||
try performExists(db)
|
||||
}
|
||||
|
||||
// MARK: - Record Comparison
|
||||
@@ -515,7 +515,7 @@ extension MutablePersistableRecord {
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
@discardableResult
|
||||
public static func deleteAll(_ db: Database) throws -> Int {
|
||||
return try all().deleteAll(db)
|
||||
try all().deleteAll(db)
|
||||
}
|
||||
|
||||
// MARK: Batch Update
|
||||
@@ -674,7 +674,7 @@ extension MutablePersistableRecord {
|
||||
/// - returns: Whether a database row was deleted.
|
||||
@discardableResult
|
||||
public static func deleteOne(_ db: Database, key: [String: DatabaseValueConvertible?]) throws -> Bool {
|
||||
return try deleteAll(db, keys: [key]) > 0
|
||||
try deleteAll(db, keys: [key]) > 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ open class Record: FetchableRecord, TableRecord, PersistableRecord {
|
||||
///
|
||||
/// See https://www.sqlite.org/lang_conflict.html
|
||||
open class var persistenceConflictPolicy: PersistenceConflictPolicy {
|
||||
return PersistenceConflictPolicy(insert: .abort, update: .abort)
|
||||
PersistenceConflictPolicy(insert: .abort, update: .abort)
|
||||
}
|
||||
|
||||
/// The default request selection.
|
||||
@@ -90,7 +90,7 @@ open class Record: FetchableRecord, TableRecord, PersistableRecord {
|
||||
/// // SELECT *, rowid FROM player
|
||||
/// try ExtendedPlayer.fetchAll(db)
|
||||
open class var databaseSelection: [SQLSelectable] {
|
||||
return [AllColumns()]
|
||||
[AllColumns()]
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ open class Record: FetchableRecord, TableRecord, PersistableRecord {
|
||||
/// false does not prevent it from turning true on subsequent modifications
|
||||
/// of the record.
|
||||
public var hasDatabaseChanges: Bool {
|
||||
get { return databaseChangesIterator().next() != nil }
|
||||
get { databaseChangesIterator().next() != nil }
|
||||
set { referenceRow = newValue ? nil : Row(self) }
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ open class Record: FetchableRecord, TableRecord, PersistableRecord {
|
||||
///
|
||||
/// See `hasDatabaseChanges` for more information.
|
||||
public var databaseChanges: [String: DatabaseValue?] {
|
||||
return Dictionary(uniqueKeysWithValues: databaseChangesIterator())
|
||||
Dictionary(uniqueKeysWithValues: databaseChangesIterator())
|
||||
}
|
||||
|
||||
// A change iterator that is used by both hasDatabaseChanges and
|
||||
|
||||
@@ -89,12 +89,12 @@ extension TableRecord {
|
||||
/// - HTTPRequest -> "httpRequest"
|
||||
/// - TOEFL -> "toefl"
|
||||
public static var databaseTableName: String {
|
||||
return defaultDatabaseTableName
|
||||
defaultDatabaseTableName
|
||||
}
|
||||
|
||||
/// Default value: `[AllColumns()]`.
|
||||
public static var databaseSelection: [SQLSelectable] {
|
||||
return [AllColumns()]
|
||||
[AllColumns()]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ extension TableRecord {
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
public static func fetchCount(_ db: Database) throws -> Int {
|
||||
return try all().fetchCount(db)
|
||||
try all().fetchCount(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,19 +12,19 @@ extension String {
|
||||
/// "player" -> "players"
|
||||
/// "players" -> "players"
|
||||
var pluralized: String {
|
||||
return Inflections.default.pluralize(self)
|
||||
Inflections.default.pluralize(self)
|
||||
}
|
||||
|
||||
/// "player" -> "player"
|
||||
/// "players" -> "player"
|
||||
var singularized: String {
|
||||
return Inflections.default.singularize(self)
|
||||
Inflections.default.singularize(self)
|
||||
}
|
||||
|
||||
/// "bar" -> "bar"
|
||||
/// "foo12" -> "foo"
|
||||
var digitlessRadical: String {
|
||||
return String(prefix(upTo: Inflections.endIndexOfDigitlessRadical(self)))
|
||||
String(prefix(upTo: Inflections.endIndexOfDigitlessRadical(self)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public struct Inflections {
|
||||
|
||||
// For testability
|
||||
var uncountables: Set<String> {
|
||||
return Set(uncountablesRegularExpressions.keys)
|
||||
Set(uncountablesRegularExpressions.keys)
|
||||
}
|
||||
|
||||
// MARK: - Initialization
|
||||
@@ -144,12 +144,12 @@ public struct Inflections {
|
||||
///
|
||||
/// Inflections.default.pluralize("player") // "players"
|
||||
public func pluralize(_ string: String) -> String {
|
||||
return inflectString(string, with: pluralizeRules)
|
||||
inflectString(string, with: pluralizeRules)
|
||||
}
|
||||
|
||||
/// Returns a singularized string.
|
||||
public func singularize(_ string: String) -> String {
|
||||
return inflectString(string, with: singularizeRules)
|
||||
inflectString(string, with: singularizeRules)
|
||||
}
|
||||
|
||||
// MARK: - Utils
|
||||
|
||||
@@ -6,7 +6,7 @@ final class LockedBox<T> {
|
||||
private var lock = NSLock()
|
||||
|
||||
var value: T {
|
||||
get { return read { $0 } }
|
||||
get { read { $0 } }
|
||||
set { write { $0 = newValue } }
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ final class LockedBox<T> {
|
||||
extension LockedBox where T: Numeric {
|
||||
@discardableResult
|
||||
func increment() -> T {
|
||||
return write { n in
|
||||
write { n in
|
||||
n += 1
|
||||
return n
|
||||
}
|
||||
@@ -38,7 +38,7 @@ extension LockedBox where T: Numeric {
|
||||
|
||||
@discardableResult
|
||||
func decrement() -> T {
|
||||
return write { n in
|
||||
write { n in
|
||||
n -= 1
|
||||
return n
|
||||
}
|
||||
|
||||
Loaded 100 of 173 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user