Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.5.0 #90

Merged
merged 175 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
b32cbd8
Add debug logging to Query and Database. Refactor a bit.
joshuawright11 Oct 3, 2022
b5813ad
Naming consistency with key and db
joshuawright11 Oct 3, 2022
a70ede6
Eager loading 2.0
joshuawright11 Dec 12, 2022
d38724d
WIP
joshuawright11 Dec 16, 2022
9c08e75
Eager load wheres and debug
joshuawright11 Dec 20, 2022
ef5f816
Cleanup
joshuawright11 Dec 20, 2022
d9a9dde
fetch
joshuawright11 Dec 20, 2022
77e695c
WIP
joshuawright11 Dec 21, 2022
b5b527e
Add pivots and through
joshuawright11 Jan 4, 2023
9abd1ac
WIP
joshuawright11 Jan 11, 2023
900a984
Through working
joshuawright11 Feb 19, 2023
6795571
Fix eager loading through relationships
joshuawright11 Feb 19, 2023
09e9a2e
Pre-Query surgery
joshuawright11 Mar 14, 2023
cce1b51
Will it blend
joshuawright11 Mar 14, 2023
58c4dbb
WIP
joshuawright11 May 31, 2023
319c910
WIP
joshuawright11 May 31, 2023
45b7a56
Update
joshuawright11 May 31, 2023
7d935c4
Finalize API
joshuawright11 Jun 2, 2023
14a692a
Remove Scratch
joshuawright11 Jun 2, 2023
96d4863
Throughs WIP
joshuawright11 Jun 2, 2023
5db5694
Brain hurts
joshuawright11 Jun 2, 2023
bc6ccdd
Fix up key defaults
joshuawright11 Jun 2, 2023
fdc289c
Finalize through
joshuawright11 Jun 2, 2023
6198217
Finish
joshuawright11 Jun 2, 2023
460cee1
Cleanup
joshuawright11 Jul 13, 2023
63ad4a2
Get throughs workign
joshuawright11 Jul 21, 2023
477248a
Cleanup
joshuawright11 Jul 21, 2023
8c28394
Cleanup
joshuawright11 Jul 21, 2023
bc2c6cf
Up to HasManyThrough
joshuawright11 Jul 21, 2023
b8b1f11
Cleanup
joshuawright11 Jul 21, 2023
7b11030
Fix BelongsToMany
joshuawright11 Jul 21, 2023
89d1454
Fix multiple HasThrough
joshuawright11 Jul 21, 2023
5bf9051
Fix multiple throughs on BelongsToThrough
joshuawright11 Jul 21, 2023
c72be57
Clean up
joshuawright11 Jul 21, 2023
377b498
Cleanup
joshuawright11 Jul 22, 2023
98a0b62
Cleanup
joshuawright11 Jul 22, 2023
d508d98
Fix eager loading & nested
joshuawright11 Jul 22, 2023
6ab7ac2
Initial key cleanup
joshuawright11 Jul 22, 2023
f2c5941
Convert to and from keys
joshuawright11 Jul 22, 2023
6d1df19
Move to and from keys to Relation
joshuawright11 Jul 22, 2023
d971d9c
Cleanup
joshuawright11 Jul 22, 2023
aa57052
Cleanup
joshuawright11 Jul 24, 2023
04e5b10
Move relationship logic to classes
joshuawright11 Jul 24, 2023
f8700ac
Fix typos
joshuawright11 Jul 24, 2023
e04f222
Clean up caching
joshuawright11 Jul 24, 2023
36d3434
Compound WIP
joshuawright11 Jul 24, 2023
a46d897
Fix caching with compound relations
joshuawright11 Jul 24, 2023
c20ff29
Clean up
joshuawright11 Jul 25, 2023
03a275b
Cleanup key inference
joshuawright11 Jul 25, 2023
f1466da
Basic CRUD
joshuawright11 Jul 25, 2023
7dfd9de
Add BelongsToMany CRUD
joshuawright11 Jul 25, 2023
2454472
Better SQLValue coercion
joshuawright11 Jul 26, 2023
91f1bab
Add data field
joshuawright11 Jul 26, 2023
5c6106d
WIP
joshuawright11 Jul 26, 2023
d72abef
Add SQLParameter
joshuawright11 Jul 26, 2023
63a3f1c
Fix
joshuawright11 Jul 26, 2023
27b6257
WIP
joshuawright11 Jul 26, 2023
999818f
WIP
joshuawright11 Jul 26, 2023
e34f4e3
Fix broken tests
joshuawright11 Jul 26, 2023
6c85f35
Cleanup
joshuawright11 Jul 27, 2023
333a156
Clean up database configs
joshuawright11 Jul 27, 2023
0a1d57d
Cleanup drivers, add escaped question marks
joshuawright11 Jul 27, 2023
c60f171
Cleanup
joshuawright11 Jul 27, 2023
0e4344c
Remove database kits
joshuawright11 Jul 27, 2023
16e0d65
Move seeding
joshuawright11 Jul 28, 2023
9077130
Updaate
joshuawright11 Jul 28, 2023
e390dd0
Merge Dialect and Grammar
joshuawright11 Jul 28, 2023
9a9c80a
Finalize SQL
joshuawright11 Jul 28, 2023
01d940f
Update
joshuawright11 Jul 28, 2023
a39bb77
Move migrations and schema to database
joshuawright11 Jul 28, 2023
b2bd7fb
Throw error if missing migration when rolling back
joshuawright11 Jul 28, 2023
976c6fa
Cleanup
joshuawright11 Jul 28, 2023
2decc08
Cleanup migrations
joshuawright11 Jul 29, 2023
b32b21d
Fix logging
joshuawright11 Jul 29, 2023
5df5b0d
Some logging cleanup
joshuawright11 Jul 29, 2023
6e426f0
Update log
joshuawright11 Jul 30, 2023
46ac3bb
Add nicer logging
joshuawright11 Jul 30, 2023
07d8033
More Service configuration
joshuawright11 Aug 1, 2023
31017fb
Cleanup Access
joshuawright11 Aug 1, 2023
9d9cbea
Wrap Services
joshuawright11 Aug 1, 2023
7eb32e2
Cleanup Commands & Query
joshuawright11 Aug 8, 2023
6dcc78a
Add && and || operators to SQLWhere.Clause
joshuawright11 Aug 9, 2023
2cdab2f
Update Database+Schema naming
joshuawright11 Aug 9, 2023
b3ed03f
Clean up APIs
joshuawright11 Aug 9, 2023
a9b3ca5
Add raw expressions
joshuawright11 Aug 10, 2023
d5a0cf9
Add Raw and Nested Queries
joshuawright11 Aug 10, 2023
8177cbc
Fix naming
joshuawright11 Aug 10, 2023
cf575db
Insert Subquery
joshuawright11 Aug 10, 2023
2ed3249
Cleanup error printing
joshuawright11 Aug 10, 2023
e912112
Start Alter
joshuawright11 Aug 10, 2023
a6849b4
Alter Column
joshuawright11 Aug 11, 2023
143f815
Add chunking and AsyncSequence
joshuawright11 Aug 11, 2023
ccfa8ed
WIP
joshuawright11 Aug 11, 2023
46887c0
Cleanup commands
joshuawright11 Aug 11, 2023
faae7a3
Add Query logging
joshuawright11 Aug 11, 2023
1c2ca5c
Cleanup
joshuawright11 Aug 11, 2023
eb64451
Cleanup ModelEnum
joshuawright11 Aug 12, 2023
19bd381
Scrap ModelBase
joshuawright11 Aug 12, 2023
ee926f5
Decode fields from model query
joshuawright11 Aug 12, 2023
fd2f023
Clean Up Model CRUD
joshuawright11 Aug 12, 2023
3805682
Add increment and decrement
joshuawright11 Aug 12, 2023
41e9cc9
Increment / Decrement for Double
joshuawright11 Aug 12, 2023
a1b2cbc
Cleanup connections
joshuawright11 Aug 12, 2023
4611671
WIP
joshuawright11 Aug 15, 2023
4c94255
WIP Dirty
joshuawright11 Aug 16, 2023
c1253ec
Add Dirtyable & KeyPathQueryable
joshuawright11 Aug 16, 2023
3c01cda
Re-enable didFetch
joshuawright11 Aug 16, 2023
2fba261
Transfer over loaded relationships
joshuawright11 Aug 16, 2023
fff1f88
Add UPSERT
joshuawright11 Aug 16, 2023
3a33dc0
Add SoftDeletes
joshuawright11 Aug 16, 2023
e4fdf28
Add SoftDeletes functions
joshuawright11 Aug 16, 2023
911108c
Kill uniqueable
joshuawright11 Aug 16, 2023
1fc631a
Add KeyPath based Query where and Dirty
joshuawright11 Aug 17, 2023
ea80965
Fix SQLConvertible conformance for Relation
joshuawright11 Aug 17, 2023
84ecdbf
Add encoding functions and fix serve command
joshuawright11 Aug 18, 2023
50d3f4e
Add Encoding support to Content
joshuawright11 Aug 18, 2023
b3a6a5c
Freshen up Seeding
joshuawright11 Aug 18, 2023
767a343
Log requests in ServeCommand
joshuawright11 Aug 21, 2023
8a2ca68
Move log to service
joshuawright11 Aug 21, 2023
00db62d
Update packages
joshuawright11 Aug 22, 2023
9b49aa0
Add compound logger
joshuawright11 Aug 22, 2023
a6c4f83
Add Xcode prettify
joshuawright11 Aug 22, 2023
30b96fc
Add sensible logging defaults
joshuawright11 Aug 23, 2023
11232e3
Wrap
joshuawright11 Aug 23, 2023
87e2e98
Finalize Configs
joshuawright11 Aug 23, 2023
3be6eef
Configs
joshuawright11 Aug 23, 2023
a6dec13
Update Env
joshuawright11 Aug 23, 2023
9078460
Cleanup
joshuawright11 Aug 23, 2023
7767d60
Fix up Scheduler
joshuawright11 Aug 23, 2023
1978073
Clean up hummingbird integration
joshuawright11 Aug 24, 2023
3a300c0
Cleanup command
joshuawright11 Aug 24, 2023
d1963b9
Cleanup
joshuawright11 Aug 24, 2023
744fd09
Prep cleanup
joshuawright11 Aug 24, 2023
12c7104
WIP
joshuawright11 Aug 24, 2023
ef6da68
First stab
joshuawright11 Aug 25, 2023
bc1d33c
Finalize HTTP
joshuawright11 Aug 26, 2023
73a931d
Decouple Job from Codable
joshuawright11 Aug 27, 2023
4d5b3f4
Queues locked in
joshuawright11 Aug 27, 2023
13db614
Events
joshuawright11 Aug 27, 2023
482bca5
Cleanup
joshuawright11 Aug 27, 2023
b87417f
A place for schedulign
joshuawright11 Aug 27, 2023
a15ddff
Till next time, messages
joshuawright11 Aug 29, 2023
affa24a
Compile errors
joshuawright11 Aug 29, 2023
056367f
Cleanup
joshuawright11 Aug 29, 2023
85463cb
WIP
joshuawright11 Aug 29, 2023
67c29f4
Compiles
joshuawright11 Aug 29, 2023
f40c312
Warnings
joshuawright11 Aug 29, 2023
4af6ec1
Lock in scheduler
joshuawright11 Aug 30, 2023
e7a915a
Fix a bunch of tests
joshuawright11 Aug 31, 2023
a208553
Woops
joshuawright11 Aug 31, 2023
7248b26
Mock filecreator
joshuawright11 Aug 31, 2023
33c9f21
Mock filecreator
joshuawright11 Aug 31, 2023
7bc59b5
Fix race
joshuawright11 Aug 31, 2023
753bb79
More tests
joshuawright11 Sep 1, 2023
79fb842
Fix tests
joshuawright11 Sep 1, 2023
eed2735
Rename
joshuawright11 Sep 1, 2023
1ec8ff6
Don't create files
joshuawright11 Sep 1, 2023
51c8f92
Bit of cleanup
joshuawright11 Sep 1, 2023
59b0ed3
Cleanup
joshuawright11 Sep 1, 2023
2b4c582
Restructure tests
joshuawright11 Sep 1, 2023
0919418
Remove stale docs and imports
joshuawright11 Sep 1, 2023
8d4c618
Docs
joshuawright11 Sep 1, 2023
c4c5934
Latest
joshuawright11 Sep 1, 2023
1f95339
Update
joshuawright11 Sep 1, 2023
86d121f
Merge branch 'main' into josh/sql-upgrades
joshuawright11 Sep 1, 2023
a76ea83
Workflow
joshuawright11 Sep 1, 2023
2f0a95a
CI
joshuawright11 Sep 1, 2023
94b059e
Hide macOS-only APIs and remove Swift 5.9 usage
joshuawright11 Sep 1, 2023
d1913ea
Fix NSRecursiveLock API
joshuawright11 Sep 1, 2023
ee07c6b
Add missing Linux APIs
joshuawright11 Sep 2, 2023
910fc9e
Add missing import
joshuawright11 Sep 2, 2023
548fdf4
Maybe that?
joshuawright11 Sep 2, 2023
3f0dcef
why
joshuawright11 Sep 2, 2023
56e59de
Cleanup
joshuawright11 Sep 2, 2023
d5791b8
Unused args
joshuawright11 Sep 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
59 changes: 29 additions & 30 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
name: Swift

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
test-macos:
if: ${{ false }} # disable until macOS 12 (with concurrency) runners are available.
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.2.app/Contents/Developer
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
test-linux:
runs-on: ubuntu-20.04
strategy:
matrix:
swift: [5.5]
container: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v2
- name: Install sqlite
run: apt-get -q update && apt-get install -y libsqlite3-dev
- name: Build
run: swift build -v --enable-test-discovery
- name: Run tests
run: swift test -v --enable-test-discovery
test-macos:
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer
steps:
- uses: actions/checkout@v3
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
test-linux:
runs-on: ubuntu-22.04
strategy:
matrix:
swift: [5.8]
container: swift:${{ matrix.swift }}
steps:
- uses: actions/checkout@v3
- name: Install sqlite
run: apt-get -q update && apt-get install -y libsqlite3-dev
- name: Build
run: swift build -v --enable-test-discovery
- name: Run tests
run: swift test -v --enable-test-discovery
47 changes: 47 additions & 0 deletions Example/App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Alchemy

@main
struct App: Application {
func boot() {
get("/stream", options: .stream) { req in
Response {
try await $0.write("foo")
try await $0.write("bar")
try await $0.write("baz")
}
}

post("user") {
try await DB.table("users").insert($0.content)
}

get("success") { _ in

}

get("bad") { _ -> Void in
throw HTTPError(.badRequest)
}

get("fail") { _ -> Void in
throw HTTPError(.internalServerError)
}

get("shutdown") { _ in
Task {
try await stop()
}
}
}

func schedule(on schedule: Scheduler) {
schedule.job(GoJob())
.everySecond()
}
}

struct GoJob: Job, Codable {
func handle(context: JobContext) async throws {
Log.warning("Hello from GoJob!")
}
}
234 changes: 234 additions & 0 deletions Example/Commands/Debug.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import Alchemy
import RediStack

struct UserDTO: Codable {
let id: Int
let name: String
let age: Int
}

enum Thing: String {
case one
case two
}

struct Debug: Command {
static let name = "debug"

func run() async throws {
//
}

func testRelationships() {
// let user = try await User.query()
// .with(\.posts.comments.likes)
// .with {
// $0.posts.with {
// $0.comments.with {
// $0.likes
// }
// }
// }
// .with(\.tokens)
// .where("id" == "user_1")
// .first()!
//
// let posts = try await user.posts()
// let comments = try await posts[0].comments()
// _ = try await comments[0].likes()
// _ = try await user.posts.comments.likes()
// let _comments: [Comment] = try await user.posts.comments.get()
// let _likes: [Like] = try await user.posts.comments.likes.get()
// let _likes1: [Like] = try await user.posts.comments.likes1.get()
// let _comments: [Comment] = try await user.posts.comments.get()
// let _comments1: [Comment] = try await user.posts.comments1.get()
// let posts = try await user.posts()
// let tokens = try await user.tokens()
// let throughTokens = try await posts.first!.tokens()
// let comments = try await user.comments()
// let friends = try await user.friends()
// let likes = try await user.likes()
// let owner = try await likes.first!.postOwner()
}
}

extension Alchemy.RedisClient {
static var testing: Alchemy.RedisClient {
.configuration(RedisConnectionPool.Configuration(
initialServerConnectionAddresses: [
try! .makeAddressResolvingHost("localhost", port: 6379)
],
maximumConnectionCount: .maximumActiveConnections(1),
connectionFactoryConfiguration: RedisConnectionPool.ConnectionFactoryConfiguration(connectionDefaultLogger: Log),
connectionRetryTimeout: .milliseconds(100)
))
}

func checkAvailable() async -> Bool {
do {
_ = try await ping().get()
return true
} catch {
return false
}
}
}


struct User: Model, Codable, KeyPathQueryable {
static var storedProperties = [
\Self.id: "id",
\Self.name: "name",
\Self.age: "age",
\Self.pet: "pet",
]

var id: PK<Int> = .new
var name: String
var age: Int
var pet: String?

var tokens: HasMany<UserToken> {
hasMany()
}

var posts: HasMany<Post> {
hasMany()
}

var comments: HasManyThrough<Comment> {
hasMany().through("posts")
}

var likes: HasManyThrough<Like> {
hasMany().through("posts").through("comments")
}

var friends: BelongsToMany<User> {
belongsToMany(pivot: "friends", pivotFrom: "user_a", pivotTo: "user_b")
}
}

struct UserToken: Model, Codable {
var id: PK<String> = .new
let token: String
let userId: String

var user: BelongsTo<User> {
belongsTo()
}
}

struct Post: Model, Codable {
var id: PK<String> = .new
let title: String
let userId: String

var comments: HasMany<Comment> {
hasMany()
}

var comments1: HasOne<Comment?> {
hasOne()
}

var tokens: HasManyThrough<UserToken> {
hasMany(from: "user_id").through("users", from: "id")
}
}

struct Comment: Model, Codable {
var id: PK<String> = .new
let text: String
let userId: String

var post: BelongsTo<Post> {
belongsTo()
}

var likes: HasMany<Like> {
hasMany()
}

var likes1: HasOne<Like> {
hasOne()
}

var postOwner: BelongsToThrough<User> {
belongsTo().through("posts")
}
}

struct Like: Model, Codable {
var id: PK<String> = .new
let commentId: String
let userId: String

var postOwner: BelongsToThrough<User> {
belongsTo().through("comments").through("posts")
}
}

struct AddStuffMigration: Migration {
func up(db: Database) async throws {
try await db.createTable("users") {
$0.increments("id").primary()
$0.string("name")
$0.int("age")
}

try await db.createTable("posts") {
$0.increments("id").primary()
$0.bigInt("user_id").references("id", on: "users").notNull()
$0.string("title")
}

try await db.createTable("user_tokens") {
$0.increments("id").primary()
$0.bigInt("user_id").references("id", on: "users").notNull()
$0.string("token")
}
}

func down(db: Database) async throws {
try await db.dropTable("posts")
try await db.dropTable("user_tokens")
try await db.dropTable("users")
}
}

struct AddStuff2Migration: Migration {
func up(db: Database) async throws {
try await db.createTable("friends") {
$0.increments("id").primary()
$0.bigInt("user_a").references("id", on: "users").notNull()
$0.bigInt("user_b").references("id", on: "users").notNull()
}

try await db.createTable("comments") {
$0.increments("id").primary()
$0.bigInt("post_id").references("id", on: "posts").notNull()
$0.bigInt("user_id").references("id", on: "users").notNull()
$0.string("text")
}
}

func down(db: Database) async throws {
try await db.dropTable("friends")
try await db.dropTable("comments")
}
}

struct AddStuff3Migration: Migration {
func up(db: Database) async throws {
try await db.createTable("likes") {
$0.increments("id").primary()
$0.bigInt("comment_id").references("id", on: "comments").notNull()
$0.bigInt("user_id").references("id", on: "users").notNull()
}
}

func down(db: Database) async throws {
try await db.dropTable("likes")
}
}
22 changes: 22 additions & 0 deletions Example/Configs/App+Caches.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Alchemy

extension Application {

/// Configurations related to your app's caches.

var caches: Caches {
Caches(

/// Your app's default Cache

default: "database",

/// Define your caches here

caches: [
"database": .database,
"redis": .redis,
]
)
}
}
23 changes: 23 additions & 0 deletions Example/Configs/App+Config.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Alchemy

extension App {

/// Configurations related to your app.

var configuration: Configuration {
Configuration(

// Define plugins your app uses here.

plugins: [
//
],

// Define any custom commands here.

commands: [
Debug.self
]
)
}
}
Loading