The SQLite framework in pure Swift package: Sqlite.swift

Source: Internet
Author: User
Tags error handling sqlite

Sqlite.swift is an operating framework that encapsulates SQLite3 using the pure Swift language.

Characteristics:

    • Simple query and parameter binding interface

    • Secure, automated type of data access

    • Implicit commit and rollback interfaces

    • Developer-friendly error handling and debugging

    • Document Perfection

    • Through extensive testing

Example code:

?
1234567891011121314151617181920212223242526272829303132333435 import SQLite let db = Database("path/to/db.sqlite3") db.execute(    "CREATE TABLE users (" +        "id INTEGER PRIMARY KEY, " +        "email TEXT NOT NULL UNIQUE, " +        "manager_id INTEGER, " +        "FOREIGN KEY(manager_id) REFERENCES users(id)" +    ")") let stmt = db.prepare("INSERT INTO users (email) VALUES (?)")for email in ["[email protected]""[email protected]"] {    stmt.run(email)}  db.totalChanges // 2db.lastChanges  // {Some 1}db.lastID       // {Some 2} for row in db.prepare("SELECT id, email FROM users") {    println(row)    // [Optional(1), Optional("[email protected]")]    // [Optional(2), Optional("[email protected]")]} db.scalar("SELECT count(*) FROM users"// {Some 2} let jr = db.prepare("INSERT INTO users (email, manager_id) VALUES (? ?)")db.transaction(    stmt.run("[email protected]"),    jr.run("[email protected]", db.lastID))
Installation

Note:SQLite.swift requires Swift 1.1 (available in Xcode 6.1).

To install Sqlite.swift:

    1. Drag the sqlite.xcodeproj file into your own project. (Submodule, clone, or download the project first.)

    2. In your target ' s Build phases, add sqlite for IOS (or sqlite Mac) to the target dependencies Build phase.

    3. ADD the appropriate sqlite.framework product to theLink Binary with Libraries build phase.

    4. Add the same sqlite.framework to a Copy Files build phase with aframeworks destination. (Add a new build phase if need be.)

Project home:http://www.open-open.com/lib/view/home/1412900499530

The SQLite framework in pure Swift package: Sqlite.swift

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.