Comments (5)
for-loop support was removed to make handling errors more compatible with swift 2 errors. Instead of a for-loop, you use the next() method:
var results = try db.prepareStatement("SELECT * FROM people")
while try results.next() {
var row = results.dictionaryValue
// or whatever you want to do with the row
}
Since it's common to simply transform a row into some object value, you can also use the selectFrom
method on the Database object, or the select
method from the compiled statement. Pass these methods a block, and they will return an array of all treated rows. No need to call next()
yourself.
from squeal.
Thank you for your response.
I have a second question: if in example you posted, i want to get values of dictionary in a String array
So i do:
var arrayValues = Array(row.values)
But values are Bindable. I search documentation to know how cast it in String (all values from my database are String) from Bindable but i dont find it.
from squeal.
@Persilos, Bindable is just a protocol, so the underlying value may be any value that implements the Bindable protocol. If you know for sure that all the Bindable values are strings, you can do:
var arrayValues = row.values.map({ $0 as String })
That will simply cast all the values to strings. If you don't know for sure that all values are strings, you can do:
var arrayValues = row.values.map({ $0 as? String })
In that case you are dealing with optional values and you need keep that in mind as you use them.
These functions are not specific to Squeal, but because Squeal returns Bindable values, you need handle using the returned data correctly.
Hope that helps.
from squeal.
There are also methods that take blocks, prefixed with select
, that are likely more efficient. And the Statement
object supports subscripting by column name or index too.
Something like:
let emails = try db.selectFrom("people") { $0["email"] as String }
// equivalent with a statement
let results = try db.prepareStatement("SELECT * FROM people")
let moreEmails = try results.select { $0["email"] as String }
from squeal.
Thanks :)
from squeal.
Related Issues (20)
- Missing required module 'sqlite_3_osx HOT 2
- Issue with Xcode 6.3 - Swift 1.2 HOT 1
- Some typos in "README.md"
- "execute" with parameters. HOT 1
- Launch app using Squeal on my device HOT 1
- Can't put Database in another folder as App HOT 3
- Xcode 6.3.1: App using Squeal crashes when run on device, but works in emulator HOT 1
- Failed to Code Sign Squeal-iOS HOT 4
- Swift 2.0 Compatibility HOT 8
- Documentation Swift 2 HOT 2
- Missing required module 'sqlite3_ios' HOT 1
- Insert or replace
- Cannot compile with whole module optimization
- Creating Database on Disk Issue HOT 1
- Swift3 under Xcode 8 HOT 2
- Swift 3 error: duplicate symbol _SQUEAL_TRANSIENT
- swift-2.3 branch: fails to do archive for generic ios devices
- Any chance of codable support being introduced to the library? HOT 2
- Migration: Table already exists
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from squeal.