Skip to content

Commit 6c6ac00

Browse files
Playground readme (#6)
* palyground reamde * gh-format
1 parent fe8ad06 commit 6c6ac00

File tree

9 files changed

+145
-52
lines changed

9 files changed

+145
-52
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ jobs:
5454
- name: Checkout
5555
uses: actions/checkout@v4
5656
- name: swift-format lint
57-
run: make lint 2>&1 | Scripts/gh-workflow.swift
57+
run: make lint 2>&1 | Scripts/gh-format.swift
5858
shell: bash

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ clean:
88
swift package clean
99
rm -rf $(OUTPUD_DIR)
1010

11+
README.md: Playgrounds/README.playground/Contents.swift
12+
cat $< | ./Scripts/markdown.swift > $@
13+
1114
# MARK: - format
1215

1316
lint:

Playgrounds/Example.playground/Contents.swift

Lines changed: 0 additions & 43 deletions
This file was deleted.

Playgrounds/Example.playground/contents.xcplayground

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*:
2+
# 🌌 SQLyra 🎼
3+
4+
[![Test](https://github.com/Alexander-Ignition/SQLyra/actions/workflows/test.yml/badge.svg)](https://github.com/Alexander-Ignition/SQLyra/actions/workflows/test.yml)
5+
[![Swift 5.9](https://img.shields.io/badge/swift-5.9-brightgreen.svg?style=flat)](https://developer.apple.com/swift)
6+
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/Alexander-Ignition/SQLyra/blob/master/LICENSE)
7+
8+
Swift SQLite wrapper.
9+
10+
[Documentation](https://alexander-ignition.github.io/SQLyra/documentation/sqlyra/)
11+
12+
- Note: this readme file is available as Xcode playground in Playgrounds/README.playground
13+
14+
## Open
15+
16+
Create database in memory for reading and writing.
17+
*/
18+
import SQLyra
19+
20+
let database = try Database.open(
21+
at: "new.db",
22+
options: [.readwrite, .memory]
23+
)
24+
/*:
25+
## Create table
26+
27+
Create table for contacts with fields `id` and `name`.
28+
*/
29+
try database.execute(
30+
"""
31+
CREATE TABLE contacts(
32+
id INT PRIMARY KEY NOT NULL,
33+
name TEXT
34+
);
35+
"""
36+
)
37+
/*:
38+
## Insert
39+
40+
Insert new contacts Paul and John.
41+
*/
42+
try database.execute("INSERT INTO contacts (id, name) VALUES (1, 'Paul');")
43+
try database.execute("INSERT INTO contacts (id, name) VALUES (2, 'John');")
44+
/*:
45+
## Select
46+
47+
Select all contacts from database.
48+
*/
49+
struct Contact: Codable {
50+
let id: Int
51+
let name: String
52+
}
53+
54+
let contacts = try database.prepare("SELECT * FROM contacts;").array(decoding: Contact.self)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='7.0' target-platform='macos' swift-version='6' display-mode='raw' buildActiveScheme='true' importAppTypes='true'/>

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,48 @@
77
Swift SQLite wrapper.
88

99
[Documentation](https://alexander-ignition.github.io/SQLyra/documentation/sqlyra/)
10+
11+
- Note: this readme file is available as Xcode playground in Playgrounds/README.playground
12+
13+
## Open
14+
15+
Create database in memory for reading and writing.
16+
```swift
17+
import SQLyra
18+
19+
let database = try Database.open(
20+
at: "new.db",
21+
options: [.readwrite, .memory]
22+
)
23+
```
24+
## Create table
25+
26+
Create table for contacts with fields `id` and `name`.
27+
```swift
28+
try database.execute(
29+
"""
30+
CREATE TABLE contacts(
31+
id INT PRIMARY KEY NOT NULL,
32+
name TEXT
33+
);
34+
"""
35+
)
36+
```
37+
## Insert
38+
39+
Insert new contacts Paul and John.
40+
```swift
41+
try database.execute("INSERT INTO contacts (id, name) VALUES (1, 'Paul');")
42+
try database.execute("INSERT INTO contacts (id, name) VALUES (2, 'John');")
43+
```
44+
## Select
45+
46+
Select all contacts from database.
47+
```swift
48+
struct Contact: Codable {
49+
let id: Int
50+
let name: String
51+
}
52+
53+
let contacts = try database.prepare("SELECT * FROM contacts;").array(decoding: Contact.self)
54+
```
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#!/usr/bin/env swift
22

3-
// Workflow commands for GitHub Actions
4-
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
5-
// Usage: xcrun swift-format lint --recursive --strict ./ 2>&1 | Scripts/gh-workflow.swift
6-
// Test: echo "Sources/SQLime/SQLParameter.swift:23:1: warning: [TrailingWhitespace] remove trailing whitespace" | Scripts/gh-workflow.swift
3+
/*
4+
Usage: xcrun swift-format lint --recursive --strict ./ 2>&1 | Scripts/gh-format.swift
5+
6+
Test: echo "Sources/SQLime/SQLParameter.swift:23:1: warning: [TrailingWhitespace] remove trailing whitespace" | Scripts/gh-workflow.swift
7+
8+
Workflow commands for GitHub Actions
9+
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
10+
*/
711

812
let regex = #/(?<file>.+\.swift):(?<line>\d+):(?<column>\d+): (?<severity>.+): \[(?<title>.+)\] (?<message>.+)/#
913
while let line = readLine() {

Scripts/markdown.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env swift
2+
3+
/*
4+
OVERVIEW: Convert Xcode Playground to markdown
5+
6+
USAGE: cat Playgrounds/Example.playground/Contents.swift | ./Scripts/markdown.swift
7+
*/
8+
9+
enum TextBlock {
10+
case unknown, code, comment
11+
}
12+
13+
var block = TextBlock.unknown
14+
15+
while let line = readLine() {
16+
if line.hasPrefix("/*") {
17+
if block == .code {
18+
print("```")
19+
}
20+
block = .comment
21+
} else if line.hasSuffix("*/") {
22+
print("```swift")
23+
block = .code
24+
} else if block == .comment {
25+
print(line.drop(while: \.isWhitespace))
26+
} else {
27+
print(line)
28+
}
29+
}
30+
if block == .code {
31+
print("```")
32+
}

0 commit comments

Comments
 (0)