Skip to content

Latest commit

 

History

History
55 lines (44 loc) · 1.48 KB

File metadata and controls

55 lines (44 loc) · 1.48 KB

🌌 SQLyra 🎼

Test Swift 5.9 GitHub license

Swift SQLite wrapper.

Documentation

this readme file is available as Xcode playground in Playgrounds/README.playground

Open

Create database in memory for reading and writing.

import SQLyra

let database = try Database.open(
    at: "new.db",
    options: [.readwrite, .memory]
)

Create table

Create table for contacts with fields id and name.

let sql = """
    CREATE TABLE contacts(
        id INT PRIMARY KEY NOT NULL,
        name TEXT
    );
    """
try database.execute(sql)

Insert

Insert new contacts Paul and John.

let insert = try database.prepare("INSERT INTO contacts (id, name) VALUES (?, ?);")
try insert.bind(parameters: 1, "Paul").execute().reset()
try insert.bind(parameters: 2, "John").execute()

Select

Select all contacts from database.

struct Contact: Codable {
    let id: Int
    let name: String
}

let select = try database.prepare("SELECT * FROM contacts;")
let contacts = try select.array(Contact.self)