Skip to content

Commit

Permalink
Merge branch 'release-2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
stack committed Aug 17, 2020
2 parents af5a782 + 65f0a2a commit b9569fe
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 47 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: objective-c

os: osx
osx_image: xcode11
osx_image: xcode11.6

xcode_project: Restructure.xcodeproj

Expand All @@ -11,22 +11,22 @@ xcode_scheme:
- Restructure tvOS

xcode_sdk:
- iphonesimulator13.0
- iphonesimulator13.6
- macosx10.15
- appletvsimulator13.0
- appletvsimulator13.4

matrix:
exclude:
- xcode_scheme: Restructure iOS
xcode_sdk: macosx10.15
- xcode_scheme: Restructure iOS
xcode_sdk: appletvsimulator13.0
xcode_sdk: appletvsimulator13.4
- xcode_scheme: Restructure macOS
xcode_sdk: iphonesimulator13.0
xcode_sdk: iphonesimulator13.6
- xcode_scheme: Restructure macOS
xcode_sdk: appletvsimulator13.0
xcode_sdk: appletvsimulator13.4
- xcode_scheme: Restructure tvOS
xcode_sdk: iphonesimulator13.0
xcode_sdk: iphonesimulator13.6
- xcode_scheme: Restructure tvOS
xcode_sdk: macosx10.15

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.1.0 2020-08-16
### Added
- `sqliteVersion` fetches the underlying SQLite version string.
- Dynamic member lookup is enabled for `Row`, allowing for direct access to values via property notation.

### Removed
- `JournalMode.off` has been removed because of defensive configs.

## 2.0.0 - 2019-09-12
### Added
- `AutoVacuum` dictates the automatic vacuuming mode.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019 Stephen H. Gerstacker
Copyright (c) 2020 Stephen H. Gerstacker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Restructure

[![Build Status](https://travis-ci.org/stack/Restructure.svg?branch=swift-5.1)](https://travis-ci.org/stack/Restructure)
![Swift 5.1](https://img.shields.io/badge/Swift-5.0-orange.svg)
[![Build Status](https://travis-ci.org/stack/Restructure.svg)](https://travis-ci.org/stack/Restructure)
![Swift 5.1](https://img.shields.io/badge/Swift-5.1-orange.svg)

Restructure is a wrapper library for [SQLite](https://sqlite.org/index.html) for
iOS, macOS, and tvOS. It's fairly opinionated, as in, it does exactly what I
Expand Down Expand Up @@ -185,6 +185,23 @@ for row in statement }
}
```


### Rows support Dynamic Member Lookup

You can extract data from a row with direct property access using Dynamic Member Lookup.

```swift
let statement = try! restructure.prepare(query: "SELECT a, b, c, d, e FROM foo LIMIT 1")

guard case let .row(row) = statement.step() else {
/// Handle error
}

let a: Int = row.a
let b: String = row.b
let c: Double = row.c
```

### Migrations

The Restructure object has a `userVersion` property to track the version of a
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/ArrayStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/10/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/AutoVacuum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 8/12/19.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/Date+Julian.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/4/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/DateStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/4/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
8 changes: 1 addition & 7 deletions Sources/Restructure/JournalMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 8/12/19.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand All @@ -20,8 +20,6 @@ public enum JournalMode: CaseIterable, PragmaRepresentable {
case memory
/// A write-ahead log is used as opposed to a rollback journal. This is the default for a file-backed database.
case wal
/// No rollback journal is used.
case off

/// Create a `JournalMode` from a SQlite representation
static func from(value: String) -> JournalMode {
Expand All @@ -36,8 +34,6 @@ public enum JournalMode: CaseIterable, PragmaRepresentable {
return .memory
case "WAL":
return .wal
case "OFF":
return .off
default:
fatalError("Unsupported JournalMode string: \(value)")
}
Expand All @@ -56,8 +52,6 @@ public enum JournalMode: CaseIterable, PragmaRepresentable {
return "MEMORY"
case .wal:
return "WAL"
case .off:
return "OFF"
}
}
}
2 changes: 1 addition & 1 deletion Sources/Restructure/PragmaRepresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 8/12/19.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
19 changes: 18 additions & 1 deletion Sources/Restructure/Restructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down Expand Up @@ -67,6 +67,23 @@ public class Restructure {
get { get(pragma: "user_version") }
set { set(pragma: "user_version", value: newValue) }
}

/// The underlying SQLite version {
public var sqliteVersion: String {
do {
let statement = try prepare(query: "SELECT sqlite_version()")
let result = statement.step()

switch result {
case let .row(row):
return row[0]
default:
fatalError("Failed to fetch sqlite_version from a result: \(result)")
}
} catch {
fatalError("Failed to fetch sqlite_version: \(error)")
}
}


// MARK: - Initialization
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/RestructureError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
21 changes: 20 additions & 1 deletion Sources/Restructure/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/4/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
import SQLite3

/// A row result from a `Statement`.
@dynamicMemberLookup
public class Row {

// MARK: - Properties
Expand Down Expand Up @@ -78,6 +79,15 @@ public class Row {

return self[Int(index)]
}

/// Returns the non-null `Structurable` value via dynamic look up
///
/// - Parameter dynamicMember: The dynamic member to look for.
///
/// - Returns: The `Structurable` value associated with the key, transformated by the underlying SQLite API if necessary.
public subscript<T: Structurable>(dynamicMember key: String) -> T {
return self[key]
}

///Returns the nullable `Structurable` value for the given index value.
///
Expand Down Expand Up @@ -106,4 +116,13 @@ public class Row {

return self[Int(index)]
}

/// Returns the nullable `Structurable` value via dynamic look up
///
/// - Parameter dynamicMember: The dynamic member to look for.
///
/// - Returns: The `Structurable` value associated with the key, transformated by the underlying SQLite API if necessary.
public subscript<T: Structurable>(dynamicMember key: String) -> T? {
return self[key]
}
}
2 changes: 1 addition & 1 deletion Sources/Restructure/RowDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/15/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/SecureDelete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 8/12/19.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/Statement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/StatementEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/10/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/StepResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/4/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/String+SQLite3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/Restructure/Structurable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/4/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import XCTest
Expand Down
9 changes: 8 additions & 1 deletion Tests/RestructureTests/RestructureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure macOS Tests
//
// Created by Stephen H. Gerstacker on 11/3/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import XCTest
Expand Down Expand Up @@ -71,6 +71,13 @@ class RestructureTests: XCTestCase {
XCTAssertNoThrow(try restructure.execute(query: "CREATE TABLE foo (a INTEGER PRIMARY KEY AUTOINCREMENT, b INT); INSERT INTO foo (b) VALUES(42);"))
XCTAssertGreaterThan(restructure.lastInsertedId, 0)
}

// MARK: - SQLite Version Tests

func testSQLiteVersionExists() {
let version = restructure.sqliteVersion
XCTAssertFalse(version.isEmpty)
}


// MARK: - Migration Tests
Expand Down
2 changes: 1 addition & 1 deletion Tests/RestructureTests/RowDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Restructure
//
// Created by Stephen H. Gerstacker on 11/30/18.
// Copyright @ 2019 Stephen H. Gerstacker. All rights reserved.
// Copyright @ 2020 Stephen H. Gerstacker. All rights reserved.
//

import XCTest
Expand Down
Loading

0 comments on commit b9569fe

Please sign in to comment.