https://github.com/Alexander-Ignition/SQLyra
Swift SQLite wrapper
https://github.com/Alexander-Ignition/SQLyra
sqlite sqlite-swift sqlite3
Last synced: 11 days ago
JSON representation
Swift SQLite wrapper
- Host: GitHub
- URL: https://github.com/Alexander-Ignition/SQLyra
- Owner: Alexander-Ignition
- License: mit
- Created: 2021-01-05T07:57:48.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-02-02T09:10:03.000Z (4 months ago)
- Last Synced: 2025-02-20T09:44:05.057Z (3 months ago)
- Topics: sqlite, sqlite-swift, sqlite3
- Language: Swift
- Homepage: https://alexander-ignition.github.io/SQLyra/documentation/sqlyra/
- Size: 98.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ SQLyra ๐ผ
[](https://github.com/Alexander-Ignition/SQLyra/actions/workflows/test.yml)
[](https://developer.apple.com/swift)
[](https://github.com/Alexander-Ignition/SQLyra/blob/master/LICENSE)Swift SQLite wrapper.
[Documentation](https://alexander-ignition.github.io/SQLyra/documentation/sqlyra/)
> this readme file is available as Xcode playground in Playgrounds/README.playground
## Open
Create database in memory for reading and writing.
```swift
import SQLyralet database = try Database.open(
at: "new.db",
options: [.readwrite, .memory]
)
```
## Create tableCreate table for contacts with fields `id` and `name`.
```swift
let sql = """
CREATE TABLE contacts(
id INT PRIMARY KEY NOT NULL,
name TEXT
);
"""
try database.execute(sql)
```
## InsertInsert new contacts Paul and John.
```swift
let insert = try database.prepare("INSERT INTO contacts (id, name) VALUES (?, ?);")
try insert.bind(parameters: 1, "Paul").execute()
try insert.bind(parameters: 2, "John").execute()
```
## SelectSelect all contacts from database.
```swift
struct Contact: Codable {
let id: Int
let name: String?
}let select = try database.prepare("SELECT * FROM contacts;")
let contacts = try select.array(Contact.self)
print(contacts)
```
## DataFrameThe [DataFrame](https://developer.apple.com/documentation/tabulardata/dataframe) from the [TabularData](https://developer.apple.com/documentation/tabulardata) framework is supported.
It can help to print the table.
```swift
let df = try select.dataFrame()
print(df)
```
```
โโโโโณโโโโโโโโณโโโโโโโโโโโ
โ โ id โ name โ
โ โ โ โ
โกโโโโโโโโโโโโโโโโโโโโโโโฉ
โ 0 โ 1 โ Paul โ
โ 1 โ 2 โ John โ
โโโโโดโโโโโโโโดโโโโโโโโโโโ
```
## LicenseMIT