Swiftpack.co - jackpal/SQLiteDataFrame as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by jackpal.
jackpal/SQLiteDataFrame 0.1.0
A Swift Package Manager Package for reading SQLite3 data into Tablular Data Framework DataFrames
โญ๏ธ 3
๐Ÿ•“ 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/jackpal/SQLiteDataFrame.git", from: "0.1.0")

SQLiteDataFrame

Extends the Tablular Data DataFrame struct to read and write to SQLite databases.

Usage

   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 โ”‚
   //   โ””โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Features

  • Creates TabularData DataFrames from SQL databases.
    • Complete control over how data is read.
  • Writes TabularData DataFrames to SQL databases.
    • Complete control over how data is written.
    • Can be used to insert, update, or delete rows in existing SQL tables in addition to creating or replacing whole tables.
  • Uses the low level Sqlite3 API. Should be compatible with any sqlite wrapper library.
  • Works with:
    • A whole table.
    • A SQL statement specified by a String.
    • A prepared sqlite3 statement.

Details of Type mapping

  • DataFrames do not support the concept of non-nullable types. Non-nullable sqlite columns are represented in the DataFrame using nullable columns.

When creating a DataFrame, the DataFrame column types are automatically created based on the SQLite column declarations. The default algorithm:

  • Recognizes the standard SQL column types using the Affinity Rules:
    • Int
    • Double
    • String
    • Blob
  • Recognizes extended types:
    • Bool
    • Date
  • Columns whose types can't be determined are given type Any
  • You can manually override the default types by using the "types:" parameter.
  • You can control the encode/decode of a type by implementing the SQLiteEncodable / SQLiteDecodable protocols.

GitHub

link
Stars: 3
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.1.0
2 years ago

First public release.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics