-
-
Notifications
You must be signed in to change notification settings - Fork 727
/
Copy pathStandardLibrary.swift
695 lines (621 loc) · 26.5 KB
/
StandardLibrary.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
#if SWIFT_PACKAGE
import CSQLite
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
import SQLite3
#endif
// MARK: - Value Types
/// Bool adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Bool: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
self = sqlite3_column_int64(sqliteStatement, index) != 0
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return (self ? 1 : 0).databaseValue
}
/// Returns a Bool initialized from *dbValue*, if possible.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Bool? {
// IMPLEMENTATION NOTE
//
// https://www.sqlite.org/lang_expr.html#booleanexpr
//
// > # Boolean Expressions
// >
// > The SQL language features several contexts where an expression is
// > evaluated and the result converted to a boolean (true or false)
// > value. These contexts are:
// >
// > - the WHERE clause of a SELECT, UPDATE or DELETE statement,
// > - the ON or USING clause of a join in a SELECT statement,
// > - the HAVING clause of a SELECT statement,
// > - the WHEN clause of an SQL trigger, and
// > - the WHEN clause or clauses of some CASE expressions.
// >
// > To convert the results of an SQL expression to a boolean value,
// > SQLite first casts the result to a NUMERIC value in the same way as
// > a CAST expression. A numeric zero value (integer value 0 or real
// > value 0.0) is considered to be false. A NULL value is still NULL.
// > All other values are considered true.
// >
// > For example, the values NULL, 0.0, 0, 'english' and '0' are all
// > considered to be false. Values 1, 1.0, 0.1, -0.1 and '1english' are
// > considered to be true.
//
// OK so we have to support boolean for all storage classes?
// Actually we won't, because of the SQLite boolean interpretation of
// strings:
//
// The doc says that "english" should be false, and "1english" should
// be true. I guess "-1english" and "0.1english" should be true also.
// And... what about "0.0e10english"?
//
// Ideally, we'd ask SQLite to perform the conversion itself, and return
// its own boolean interpretation of the string. Unfortunately, it looks
// like it is not so easy...
//
// So we could take a short route, and assume all strings are false,
// since most strings are falsey for SQLite.
//
// Considering all strings falsey is unfortunately very
// counter-intuitive. This is not the correct way to tackle the boolean
// problem.
//
// Instead, let's use the fact that the BOOLEAN typename has Numeric
// affinity (https://www.sqlite.org/datatype3.html), and that the doc
// says:
//
// > SQLite does not have a separate Boolean storage class. Instead,
// > Boolean values are stored as integers 0 (false) and 1 (true).
//
// So we extract bools from Integer and Real only. Integer because it is
// the natural boolean storage class, and Real because Numeric affinity
// store big numbers as Real.
switch dbValue.storage {
case .int64(let int64):
return (int64 != 0)
case .double(let double):
return (double != 0.0)
default:
return nil
}
}
}
/// Int adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Int: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = Int(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to Int")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// Int8 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Int8: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = Int8(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to Int8")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// Int16 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Int16: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = Int16(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to Int16")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// Int32 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Int32: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = Int32(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to Int32")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Int64: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
self = sqlite3_column_int64(sqliteStatement, index)
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return DatabaseValue(storage: .int64(self))
}
/// Returns an Int64 initialized from *dbValue*, if possible.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Int64? {
switch dbValue.storage {
case .int64(let int64):
return int64
case .double(let double):
guard double >= Double(Int64.min) else { return nil }
guard double < Double(Int64.max) else { return nil }
return Int64(double)
default:
return nil
}
}
}
/// UInt adopts DatabaseValueConvertible and StatementColumnConvertible.
extension UInt: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = UInt(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to UInt")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// UInt8 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension UInt8: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = UInt8(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to UInt8")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// UInt16 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension UInt16: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = UInt16(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to UInt16")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// UInt32 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension UInt32: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = UInt32(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to UInt32")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// UInt64 adopts DatabaseValueConvertible and StatementColumnConvertible.
extension UInt64: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
let int64 = sqlite3_column_int64(sqliteStatement, index)
if let v = UInt64(exactly: int64) {
self = v
} else {
fatalError("could not convert database value \(int64) to UInt64")
}
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return 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) }
}
}
/// Double adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Double: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
self = sqlite3_column_double(sqliteStatement, index)
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return DatabaseValue(storage: .double(self))
}
/// Returns a Double initialized from *dbValue*, if possible.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Double? {
switch dbValue.storage {
case .int64(let int64):
return Double(int64)
case .double(let double):
return double
default:
return nil
}
}
}
/// Float adopts DatabaseValueConvertible and StatementColumnConvertible.
extension Float: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
self = Float(sqlite3_column_double(sqliteStatement, index))
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return Double(self).databaseValue
}
/// Returns a Float initialized from *dbValue*, if possible.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> Float? {
switch dbValue.storage {
case .int64(let int64):
return Float(int64)
case .double(let double):
return Float(double)
default:
return nil
}
}
}
/// String adopts DatabaseValueConvertible and StatementColumnConvertible.
extension String: DatabaseValueConvertible, StatementColumnConvertible {
/// Returns a value initialized from a raw SQLite statement pointer.
///
/// - parameters:
/// - sqliteStatement: A pointer to an SQLite statement.
/// - index: The column index.
public init(sqliteStatement: SQLiteStatement, index: Int32) {
self = String(cString: sqlite3_column_text(sqliteStatement, Int32(index))!)
}
/// Returns a value that can be stored in the database.
public var databaseValue: DatabaseValue {
return DatabaseValue(storage: .string(self))
}
/// Returns a String initialized from *dbValue*, if possible.
public static func fromDatabaseValue(_ dbValue: DatabaseValue) -> String? {
switch dbValue.storage {
case .string(let string):
return string
default:
return nil
}
}
}
// MARK: - SQL Functions
extension DatabaseFunction {
/// An SQL function that returns the Swift built-in capitalized
/// String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// capitalized:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.capitalized)
/// let names = try String.fetchAll(dbQueue, request) // [String]
public static let capitalize = DatabaseFunction("swiftCapitalizedString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.capitalized
}
/// An SQL function that returns the Swift built-in lowercased
/// String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// lowercased:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.lowercased())
/// let names = try String.fetchAll(dbQueue, request) // [String]
public static let lowercase = DatabaseFunction("swiftLowercaseString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.lowercased()
}
/// An SQL function that returns the Swift built-in uppercased
/// String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// uppercased:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.uppercased())
/// let names = try String.fetchAll(dbQueue, request) // [String]
public static let uppercase = DatabaseFunction("swiftUppercaseString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.uppercased()
}
}
extension DatabaseFunction {
/// An SQL function that returns the Swift built-in
/// localizedCapitalized String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// localizedCapitalized:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.localizedCapitalized)
/// let names = try String.fetchAll(dbQueue, request) // [String]
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
public static let localizedCapitalize = DatabaseFunction("swiftLocalizedCapitalizedString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.localizedCapitalized
}
/// An SQL function that returns the Swift built-in
/// localizedLowercased String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// localizedLowercased:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.localizedLowercased)
/// let names = try String.fetchAll(dbQueue, request) // [String]
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
public static let localizedLowercase = DatabaseFunction("swiftLocalizedLowercaseString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.localizedLowercase
}
/// An SQL function that returns the Swift built-in
/// localizedUppercased String property.
///
/// The function returns NULL for non-strings values.
///
/// This function is automatically added by GRDB to your database
/// connections. It is the function used by the query interface's
/// localizedUppercased:
///
/// let nameColumn = Column("name")
/// let request = Player.select(nameColumn.localizedUppercased)
/// let names = try String.fetchAll(dbQueue, request) // [String]
@available(iOS 9.0, OSX 10.11, watchOS 3.0, *)
public static let localizedUppercase = DatabaseFunction("swiftLocalizedUppercaseString", argumentCount: 1, pure: true) { dbValues in
guard let string = String.fromDatabaseValue(dbValues[0]) else {
return nil
}
return string.localizedUppercase
}
}
// MARK: - SQLite Collations
extension DatabaseCollation {
// Here we define a set of predefined collations.
//
// We should avoid renaming those collations, because database created with
// earlier versions of the library may have used those collations in the
// definition of tables. A renaming would prevent SQLite to find the
// collation.
//
// Yet we're not absolutely stuck: we could register support for obsolete
// collation names with sqlite3_collation_needed().
// See https://www.sqlite.org/capi3ref.html#sqlite3_collation_needed
/// A collation, or SQL string comparison function, that compares strings
/// according to the the Swift built-in == and <= operators.
///
/// This collation is automatically added by GRDB to your database
/// connections.
///
/// You can use it when creating database tables:
///
/// let collationName = DatabaseCollation.caseInsensitiveCompare.name
/// dbQueue.execute(
/// "CREATE TABLE players (" +
/// "name TEXT COLLATE \(collationName)" +
/// ")"
/// )
public static let unicodeCompare = DatabaseCollation("swiftCompare") { (lhs, rhs) in
return (lhs < rhs) ? .orderedAscending : ((lhs == rhs) ? .orderedSame : .orderedDescending)
}
/// A collation, or SQL string comparison function, that compares strings
/// according to the the Swift built-in caseInsensitiveCompare(_:) method.
///
/// This collation is automatically added by GRDB to your database
/// connections.
///
/// You can use it when creating database tables:
///
/// let collationName = DatabaseCollation.caseInsensitiveCompare.name
/// dbQueue.execute(
/// "CREATE TABLE players (" +
/// "name TEXT COLLATE \(collationName)" +
/// ")"
/// )
public static let caseInsensitiveCompare = DatabaseCollation("swiftCaseInsensitiveCompare") { (lhs, rhs) in
return lhs.caseInsensitiveCompare(rhs)
}
/// A collation, or SQL string comparison function, that compares strings
/// according to the the Swift built-in localizedCaseInsensitiveCompare(_:) method.
///
/// This collation is automatically added by GRDB to your database
/// connections.
///
/// You can use it when creating database tables:
///
/// let collationName = DatabaseCollation.localizedCaseInsensitiveCompare.name
/// dbQueue.execute(
/// "CREATE TABLE players (" +
/// "name TEXT COLLATE \(collationName)" +
/// ")"
/// )
public static let localizedCaseInsensitiveCompare = DatabaseCollation("swiftLocalizedCaseInsensitiveCompare") { (lhs, rhs) in
return lhs.localizedCaseInsensitiveCompare(rhs)
}
/// A collation, or SQL string comparison function, that compares strings
/// according to the the Swift built-in localizedCompare(_:) method.
///
/// This collation is automatically added by GRDB to your database
/// connections.
///
/// You can use it when creating database tables:
///
/// let collationName = DatabaseCollation.localizedCompare.name
/// dbQueue.execute(
/// "CREATE TABLE players (" +
/// "name TEXT COLLATE \(collationName)" +
/// ")"
/// )
public static let localizedCompare = DatabaseCollation("swiftLocalizedCompare") { (lhs, rhs) in
return lhs.localizedCompare(rhs)
}
/// A collation, or SQL string comparison function, that compares strings
/// according to the the Swift built-in localizedStandardCompare(_:) method.
///
/// This collation is automatically added by GRDB to your database
/// connections.
///
/// You can use it when creating database tables:
///
/// let collationName = DatabaseCollation.localizedStandardCompare.name
/// dbQueue.execute(
/// "CREATE TABLE players (" +
/// "name TEXT COLLATE \(collationName)" +
/// ")"
/// )
public static let localizedStandardCompare = DatabaseCollation("swiftLocalizedStandardCompare") { (lhs, rhs) in
return lhs.localizedStandardCompare(rhs)
}
}