Documentation

This commit is contained in:
Gwendal Roué committed 2015-09-23 22:19:47 +02:00
1 parent 5b24b90d58
commit d153b5e91b
5 files changed
+29 -54

No files matched your search

@@ -4,8 +4,8 @@
Types that adopt DatabaseValueConvertible can be initialized from database
values.
The protocol comes with built-in methods that allow to fetch lazy sequences,
arrays, or single instances:
The protocol comes with built-in methods that allow to fetch sequences, arrays,
or single instances:
String.fetch(db, "SELECT name FROM ...", arguments:...) // DatabaseSequence<String?>
String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?]
@@ -38,8 +38,8 @@ public protocol DatabaseValueConvertible {
Types that adopt DatabaseValueConvertible can be initialized from database
values.
The protocol comes with built-in methods that allow to fetch lazy sequences,
arrays, or single instances:
The protocol comes with built-in methods that allow to fetch sequences, arrays,
or single instances:
String.fetch(db, "SELECT name FROM ...", arguments:...) // DatabaseSequence<String?>
String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?]
@@ -58,7 +58,7 @@ public extension DatabaseValueConvertible {
/**
TODO
Fetches a lazy sequence of DatabaseValueConvertible values.
Fetches a sequence of DatabaseValueConvertible values.
let statement = db.selectStatement("SELECT name FROM ...")
let names = String.fetch(statement) // DatabaseSequence<String?>
@@ -77,7 +77,7 @@ public extension DatabaseValueConvertible {
- parameter statement: The statement to run.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of values.
- returns: A sequence of values.
*/
public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Self?> {
return statement.fetch(arguments: arguments) {
@@ -120,7 +120,7 @@ public extension DatabaseValueConvertible {
// MARK: - Fetching From Database
/**
Fetches a lazy sequence of DatabaseValueConvertible values.
Fetches a sequence of DatabaseValueConvertible values.
let names = String.fetch(db, "SELECT name FROM ...") // DatabaseSequence<String?>
@@ -139,7 +139,7 @@ public extension DatabaseValueConvertible {
- parameter db: A Database.
- parameter sql: An SQL query.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of values.
- returns: A sequence of values.
*/
public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self?> {
return fetch(db.selectStatement(sql), arguments: arguments)
@@ -183,7 +183,7 @@ public extension DatabaseValueConvertible where Self: MetalType {
/**
TODO
Fetches a lazy sequence of DatabaseValueConvertible values.
Fetches a sequence of DatabaseValueConvertible values.
let statement = db.selectStatement("SELECT name FROM ...")
let names = String.fetch(statement) // DatabaseSequence<String?>
@@ -202,7 +202,7 @@ public extension DatabaseValueConvertible where Self: MetalType {
- parameter statement: The statement to run.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of values.
- returns: A sequence of values.
*/
public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Self?> {
return statement.fetch(arguments: arguments) {
@@ -250,7 +250,7 @@ public extension DatabaseValueConvertible where Self: MetalType {
// MARK: - Fetching From Database
/**
Fetches a lazy sequence of DatabaseValueConvertible values.
Fetches a sequence of DatabaseValueConvertible values.
let names = String.fetch(db, "SELECT name FROM ...") // DatabaseSequence<String?>
@@ -269,7 +269,7 @@ public extension DatabaseValueConvertible where Self: MetalType {
- parameter db: A Database.
- parameter sql: An SQL query.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of values.
- returns: A sequence of values.
*/
public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self?> {
return fetch(db.selectStatement(sql), arguments: arguments)
+6 -32
View File
@@ -4,8 +4,8 @@ Types that adopt RowConvertible can be initialized from a database Row.
let row = Row.fetchOne(db, "SELECT ...")!
let person = Person(row: row)
The protocol comes with built-in methods that allow to fetch lazy sequences,
arrays, or single instances:
The protocol comes with built-in methods that allow to fetch sequences, arrays,
or single instances:
Person.fetch(db, "SELECT ...", arguments:...) // DatabaseSequence<Person>
Person.fetchAll(db, "SELECT ...", arguments:...) // [Person]
@@ -39,7 +39,7 @@ extension RowConvertible {
/**
TODO
Fetches a lazy sequence.
Fetches a sequence.
let statement = db.selectStatement("SELECT * FROM persons")
let persons = Person.fetch(statement) // DatabaseSequence<Person>
@@ -58,7 +58,7 @@ extension RowConvertible {
- parameter statement: The statement to run.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence.
- returns: A sequence.
*/
public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
// Metal rows can be reused. And reusing them yields better performance.
@@ -105,7 +105,7 @@ extension RowConvertible {
// MARK: - Fetching From Database
/**
Fetches a lazy sequence.
Fetches a sequence.
let persons = Person.fetch(db, "SELECT * FROM persons") // DatabaseSequence<Person>
@@ -124,38 +124,12 @@ extension RowConvertible {
- parameter db: A Database.
- parameter sql: An SQL query.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence.
- returns: A sequence.
*/
public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
return fetch(db.selectStatement(sql), arguments: arguments)
}
// /**
// Fetches a lazy sequence.
//
// let persons = Person.fetch(db, "SELECT * FROM persons") // DatabaseSequence<Person>
//
// The returned sequence can be consumed several times, but it may yield
// different results, should database changes have occurred between two
// generations:
//
// let persons = Person.fetch(db, "SELECT * FROM persons")
// Array(persons).count // 3
// db.execute("DELETE ...")
// Array(persons).count // 2
//
// If the database is modified while the sequence is iterating, the remaining
// elements are undefined.
//
// - parameter db: A Database.
// - parameter sql: An SQL query.
// - parameter arguments: Optional statement arguments.
// - returns: A lazy sequence.
// */
// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
// return fetch(db.selectStatement(sql), arguments: arguments)
// }
/**
Fetches an array.
+8 -8
View File
@@ -330,7 +330,7 @@ public class Row: CollectionType {
/**
TODO
Returns a row generator that provides fast but unsafe access to database
Returns a row sequence that provides fast but unsafe access to database
values:
for row in MetalRow.fetch(db, "SELECT id, name FROM persons") {
@@ -338,19 +338,19 @@ public class Row: CollectionType {
let name = row.string(atIndex: 1)
}
The returned generator is *unsafe* because it must be used with extra care,
The returned sequence is *unsafe* because it must be used with extra care,
and GRDB.swift will not prevent invalid usage.
- It MUST be iterated right away. Do not reserve it, do not wrap it in an
Array.
Granted with those constraints, the unsafe generator grants extra speed for
Granted with those constraints, the unsafe sequence grants extra speed for
the typed row accessors Row.int64(atIndex:), Row.string(atIndex:), etc.
- parameter db: A Database.
- parameter sql: An SQL query.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of rows.
- returns: A sequence of rows.
*/
public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Row> {
// Metal rows can be reused. And reusing them yields better performance.
@@ -398,7 +398,7 @@ public class Row: CollectionType {
/**
TODO
Returns a row generator that provides fast but unsafe access to database
Returns a row sequence that provides fast but unsafe access to database
values:
for row in Row.fetch(db, "SELECT id, name FROM persons") {
@@ -406,19 +406,19 @@ public class Row: CollectionType {
let name = row.string(atIndex: 1)
}
The returned generator is *unsafe* because it must be used with extra care,
The returned sequence is *unsafe* because it must be used with extra care,
and GRDB.swift will not prevent invalid usage.
- It MUST be iterated right away. Do not reserve it, do not wrap it in an
Array.
Granted with those constraints, the unsafe generator grants extra speed for
Granted with those constraints, the unsafe sequence grants extra speed for
the typed row accessors Row.int64(atIndex:), Row.string(atIndex:), etc.
- parameter db: A Database.
- parameter sql: An SQL query.
- parameter arguments: Optional statement arguments.
- returns: A lazy sequence of rows.
- returns: A sequence of rows.
*/
public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Row> {
return fetch(db.selectStatement(sql), arguments: arguments)
+1 -2
View File
@@ -1,5 +1,4 @@
/// A nicer name than COpaquePointer for SQLite statement handle
/// A nicer name than COpaquePointer for SQLite statement handle (TODO: better documentation)
public typealias SQLiteStatement = COpaquePointer
private let SQLITE_TRANSIENT = unsafeBitCast(COpaquePointer(bitPattern: -1), sqlite3_destructor_type.self)
+2
View File
@@ -8,3 +8,5 @@
- [ ] Write test for how a fetched sequence should behave. It should contains the expected values. It can be restarted. Some of those are already written.
- [ ] Update documentation when they metal rows are exposed, so that user is encouraged copying them.
- [ ] Metal: How does the code look like when one iterates metal row and extracts NSData without copy?
- [ ] Metal: See what can be done about testRowSequenceCanBeIteratedIndependentlyFromSQLiteStatement()
- [ ] Turn DatabaseIntRepresentable and DatabaseStringRepresentable into MetalType