Extends the Tablular Data DataFrame struct to read and write to SQLite databases.
import SQLiteDataFrame
import TabularData
// Create a sql table for demo purposes.
var db: SQLiteConnection!
defer { sqlite3_close(db) }
try checkSQLite(sqlite3_open(":memory:", &db))
try db.exec("""
create table tasks (
description text not null,
done bool default false not null,
date DATE default CURRENT_TIMESTAMP not null
);
insert into tasks (description) values ('Walk dog');
insert into tasks (description) values ('Drink milk');
insert into tasks (description) values ('Write code');
""")
// Create a DataFrame from the results of the select statement.
let dataFrame = try DataFrame(connection: db, statement:"select rowid, description, done, date from tasks order by rowid;")
print(dataFrame)
// Prints:
// โโโโโณโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// โ โ rowid โ description โ done โ date โ
// โ โ <Int> โ <String> โ <Bool> โ <Date> โ
// โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
// โ 0 โ 1 โ Walk dog โ false โ 2022-01-04 15:30:12 +0000 โ
// โ 1 โ 2 โ Drink milk โ false โ 2022-01-04 15:30:12 +0000 โ
// โ 2 โ 3 โ Write code โ false โ 2022-01-04 15:30:12 +0000 โ
// โโโโโดโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
When creating a DataFrame, the DataFrame column types are automatically created based on the SQLite column declarations. The default algorithm:
link |
Stars: 3 |
Last commit: 2 years ago |
First public release.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics