Skip to content

Commit d5c4976

Browse files
committed
Update README.md
1 parent 10faa1d commit d5c4976

1 file changed

Lines changed: 39 additions & 24 deletions

File tree

README.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Swift](https://img.shields.io/badge/Swift-5-orange.svg?style=flat)](https://swift.org)
44
[![Platform](https://img.shields.io/badge/platform-iOS%20%7C%20macOS%20%7C%20watchOS%20%7C%20tvOS-lightgrey.svg)](https://developer.apple.com/swift/)
55

6-
A simple wrapper around the SQLite3 API.
6+
A simple wrapper around SQLite3.
77

88
Installation
99
------------
@@ -22,7 +22,7 @@ Enter Package URL: https://github.com/denissimon/SQLiteAdapter
2222
To install SQLiteAdapter using [CocoaPods](https://cocoapods.org), add this line to your `Podfile`:
2323

2424
```ruby
25-
pod 'SQLiteAdapter', '~> 0.6'
25+
pod 'SQLiteAdapter', '~> 0.7'
2626
```
2727

2828
#### Carthage
@@ -84,36 +84,46 @@ try? sqlite?.createTable(sql: statementCreateTable)
8484
```swift
8585
do {
8686
var sql = "INSERT INTO \(sqlTable.name) (json, updated) VALUES (?, ?);"
87-
let _ = try sqlite.insertRow(sql: sql, params: ["someJson", Date()])
87+
try sqlite.insertRow(sql: sql, params: ["someJson", Date()])
8888

8989
sql = "INSERT INTO \(sqlTable.name) (json, updated) VALUES (?, ?), (?, ?);"
90-
let lastInsertID = try sqlite.insertRow(sql: sql, params: [nil, Date(), nil, Date()])
91-
assert(lastInsertID == 3)
90+
let (changes, lastInsertID) = try sqlite.insertRow(sql: sql, params: [nil, Date(), nil, Date()])
91+
assert((changes, lastInsertID) == (2, 3))
9292

9393
sql = "UPDATE \(sqlTable.name) SET isDeleted = ?, updated = ? WHERE \(sqlTable.primaryKey) IN (2, 3)"
9494
try sqlite.updateRow(sql: sql, params: [true, Date()])
9595
assert(sqlite.changes == 2)
9696

9797
sql = "SELECT * FROM \(sqlTable.name) WHERE isDeleted = ?"
98-
let rows = try sqlite.getRow(from: sqlTable, sql: sql, params: [true])
99-
assert(rows.count == 2)
98+
if let rows = try sqlite.getRow(from: sqlTable, sql: sql, params: [true])
99+
assert(rows.count == 2)
100+
}
100101

101102
try sqlite.deleteByID(in: sqlTable, id: 2)
102103
try sqlite.deleteByID(in: sqlTable, id: 3)
103104

104105
let rowCount = try sqlite.getRowCount(in: sqlTable)
105106
assert(rowCount == 1)
106107

107-
var row = try sqlite.getFirstRow(from: sqlTable)
108-
assert(row[0].value as! Int == 1) // "id" INTEGER NOT NULL
109-
assert(row[1].value as? String == "someJson") // "json" TEXT NULL
110-
assert(row[2].value as! Bool == false) // "isDeleted" BOOLEAN DEFAULT 0 NOT NULL
111-
assert((row[3].value as! Date) <= Date()) // "updated" DATETIME NOT NULL
108+
if let row = try sqlite.getFirstRow(from: sqlTable) {
109+
assert(row[0].value as! Int == 1) // "id" INTEGER NOT NULL
110+
assert(row[1].value as? String == "someJson") // "json" TEXT NULL
111+
assert(row[2].value as! Bool == false) // "isDeleted" BOOLEAN DEFAULT 0 NOT NULL
112+
assert((row[3].value as! Date) <= Date()) // "updated" DATETIME NOT NULL
113+
}
112114
} catch {
113-
print("SQLite:", error.localizedDescription)
115+
print("SQLite:", error)
114116
}
115117
```
116118

119+
```swift
120+
// Read methods return nil if no rows have been read
121+
let row = try sqlite.getByID(from: sqlTable, id: 10) // -> nil
122+
123+
// Insert, update, and delete methods return the number of changes made
124+
let changes = try sqlite.deleteAllRows(in: sqlTable) // -> 1
125+
```
126+
117127
**Optional settings:**
118128

119129
```swift
@@ -148,22 +158,27 @@ func checkIfIndexExists(in table: SQLTable, indexName: String) throws -> Bool
148158
func dropIndex(in table: SQLTable, forColumn columnName: String) throws
149159
func beginTransaction() throws
150160
func endTransaction() throws
151-
func insertRow(sql: String, params: [Any]?) throws -> Int
152-
func updateRow(sql: String, params: [Any]?) throws
153-
func deleteRow(sql: String, params: [Any]?) throws
154-
func deleteByID(in table: SQLTable, id: Int) throws
155-
func deleteAllRows(in table: SQLTable, vacuum: Bool, resetAutoincrement: Bool) throws
161+
func insertRow(sql: String, params: [Any]?) throws -> (Int, Int)
162+
func updateRow(sql: String, params: [Any]?) throws -> Int
163+
func deleteRow(sql: String, params: [Any]?) throws -> Int
164+
func deleteByID(in table: SQLTable, id: Int) throws -> Int
165+
func deleteAllRows(in table: SQLTable, vacuum: Bool, resetAutoincrement: Bool) throws -> Int
156166
func getRowCount(in table: SQLTable) throws -> Int
157167
func getRowCountWithCondition(sql: String, params: [Any]?) throws -> Int
158-
func getRow(from table: SQLTable, sql: String, params: [Any]?) throws -> [SQLValues]
159-
func getAllRows(from table: SQLTable) throws -> [SQLValues]
160-
func getByID(from table: SQLTable, id: Int) throws -> SQLValues
161-
func getFirstRow(from table: SQLTable) throws -> SQLValues
162-
func getLastRow(from table: SQLTable) throws -> SQLValues
168+
func getRow(from table: SQLTable, sql: String, params: [Any]?) throws -> [SQLValues]?
169+
func getAllRows(from table: SQLTable) throws -> [SQLValues]?
170+
func getByID(from table: SQLTable, id: Int) throws -> SQLValues?
171+
func getFirstRow(from table: SQLTable) throws -> SQLValues?
172+
func getLastRow(from table: SQLTable) throws -> SQLValues?
163173
func vacuum() throws
164-
func query(sql: String, params: [Any]?) throws
174+
func query(sql: String, params: [Any]?) throws -> Int
165175
```
166176

177+
Requirements
178+
------------
179+
180+
iOS 12.0+, macOS 10.13.0+, tvOS 12.0+, watchOS 4.0+
181+
167182
License
168183
-------
169184

0 commit comments

Comments
 (0)