Skip to content

Commit e508eda

Browse files
committed
Update README.md
1 parent 47cf02c commit e508eda

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,51 @@ if let rows = try table.select(Where: ["id=",90, "or id=",91, "or id>",95]) {
163163
if let rows = try table.select(["str", "uint8_array"], Where: ["id=",90, "or id=",91, "or id>",95]) {
164164
print(rows)
165165
}
166+
```
167+
### Create a MySQL Connection Pool
168+
```swift
169+
// create a connection pool with 10 connections using con as prototype
170+
let connPool = try MySQL.ConnectionPool(num: 10, connection: con)
171+
//create a table object using the connection
172+
let table = MySQL.Table(tableName: "xctest_conn_pool", connection: con)
173+
// drop the table if it exists
174+
try table.drop()
175+
176+
// declare a Swift object
177+
class obj {
178+
var id:Int?
179+
var val : Int = 1
180+
}
181+
182+
// create a new object
183+
let o = obj()
184+
// create a new MySQL Table using the object
185+
try table.create(o, primaryKey: "id", autoInc: true)
186+
187+
// do 500 async inserts using the connections pool
188+
for i in 1...500 {
189+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), {
190+
//get a connection from the pool
191+
if let c = connPool.getConnection() {
192+
// get a Table reference using the connection from the pool
193+
let t = MySQL.Table(tableName: "xctest_conn_pool", connection: c)
194+
do {
195+
let o = obj()
196+
o.val = i
197+
// insert the object
198+
try t.insert(o)
199+
}
200+
catch {
201+
print(error)
202+
XCTAssertNil(error)
203+
connPool.free(c)
204+
}
205+
// release the connection to the pool
206+
connPool.free(c)
207+
}
208+
})
209+
}
210+
166211
```
167212

168213
### CocoaPods.

0 commit comments

Comments
 (0)