Skip to content

Commit 6380293

Browse files
committed
Removed with: parameter name
1 parent a44f1d2 commit 6380293

27 files changed

Lines changed: 100 additions & 81 deletions

Example/Todo/Extensions/DB+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension DB {
2424
at: directoryURL,
2525
withIntermediateDirectories: true
2626
)
27-
self = try DB(url: dbURL)
27+
self = try DB(url: dbURL, adapters: DB.Adapters())
2828
}
2929
}
3030
}

Example/Todo/TodoForm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct TodoForm: View {
4444
TodoForm(
4545
model: TodoFormModel(
4646
mode: .update(.mock()),
47-
todoQueries: TodoQueriesNoop(),
47+
todoQueries: .noop(),
4848
complete: {}
4949
)
5050
)

Example/Todo/TodoFormModel.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Foundation
1212
final class TodoFormModel: Identifiable {
1313
let mode: Mode
1414
let complete: () -> Void
15-
let todoQueries: any TodoQueries
15+
let todoQueries: TodoQueries
1616

1717
var name = ""
1818
var error: Error?
@@ -24,7 +24,7 @@ final class TodoFormModel: Identifiable {
2424

2525
init(
2626
mode: Mode,
27-
todoQueries: any TodoQueries,
27+
todoQueries: TodoQueries,
2828
complete: @escaping () -> Void
2929
) {
3030
self.mode = mode
@@ -43,11 +43,9 @@ final class TodoFormModel: Identifiable {
4343
do {
4444
switch mode {
4545
case .create:
46-
_ = try await todoQueries.insertTodo
47-
.execute(with: name)
46+
_ = try await todoQueries.insertTodo.execute(name)
4847
case .update(let todo):
49-
try await todoQueries.updateTodo
50-
.execute(name: name, id: todo.id)
48+
try await todoQueries.updateTodo.execute(name: name, id: todo.id)
5149
}
5250

5351
complete()

Example/Todo/TodoList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct TodoList: View {
6262
NavigationStack {
6363
TodoList(
6464
model: TodoListModel(
65-
todoQueries: TodoQueriesNoop(
65+
todoQueries: .noop(
6666
selectTodos: Queries.Just([
6767
.mock(name: "Walk Dog"),
6868
.mock(name: "Clean Kitchen", completed: .now),

Example/Todo/TodoListModel.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import Foundation
1010
@Observable
1111
@MainActor
1212
final class TodoListModel {
13-
let todoQueries: any TodoQueries
13+
let todoQueries: TodoQueries
1414

1515
var todos: [Todo] = []
1616
var error: Error?
1717
var formModel: TodoFormModel?
1818

19-
init(todoQueries: any TodoQueries) {
19+
init(todoQueries: TodoQueries) {
2020
self.todoQueries = todoQueries
2121
}
2222

@@ -32,8 +32,7 @@ final class TodoListModel {
3232

3333
func toggle(todo: Todo) async {
3434
do {
35-
try await todoQueries.toggleTodo
36-
.execute(with: todo.id)
35+
try await todoQueries.toggleTodo.execute(todo.id)
3736
} catch {
3837
self.error = error
3938
}

Example/TodoTests/TodoFormTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct TodoFormTests {
1818

1919
let model = TodoFormModel(
2020
mode: .create,
21-
todoQueries: TodoQueriesNoop(insertTodo: insertTodo),
21+
todoQueries: TodoQueries.noop(insertTodo: insertTodo),
2222
complete: {}
2323
)
2424

@@ -32,7 +32,7 @@ struct TodoFormTests {
3232

3333
let model = TodoFormModel(
3434
mode: .update(.mock()),
35-
todoQueries: TodoQueriesNoop(updateTodo: updateTodo),
35+
todoQueries: TodoQueries.noop(updateTodo: updateTodo),
3636
complete: {}
3737
)
3838

Example/TodoTests/TodoListTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct TodoListTests {
1616
@Test func todosAreSetOnLoad() async {
1717
let todos: [Todo] = [.mock(), .mock()]
1818
let selectTodos = Queries.Test<(), [Todo]>(todos)
19-
let model = TodoListModel(todoQueries: TodoQueriesNoop(selectTodos: selectTodos))
19+
let model = TodoListModel(todoQueries: .noop(selectTodos: selectTodos))
2020

2121
await model.load()
2222

@@ -26,7 +26,7 @@ struct TodoListTests {
2626

2727
@Test func loadFailureSetsError() async {
2828
let model = TodoListModel(
29-
todoQueries: TodoQueriesNoop(
29+
todoQueries: .noop(
3030
// Queries.Fail always throws an error
3131
selectTodos: Queries.Fail()
3232
)
@@ -39,7 +39,7 @@ struct TodoListTests {
3939

4040
@Test func toggleTodoUpdatesDB() async {
4141
let toggleTodo = Queries.Test<Todo.ID, ()>()
42-
let model = TodoListModel(todoQueries: TodoQueriesNoop(toggleTodo: toggleTodo))
42+
let model = TodoListModel(todoQueries: .noop(toggleTodo: toggleTodo))
4343

4444
await model.toggle(todo: .mock())
4545

Sources/Compiler/Gen/SwiftLanguage.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ public struct SwiftLanguage: Language {
685685
writer.write(") async throws -> Output ")
686686

687687
writer.braces {
688-
writer.write(line: "try await execute(with: ", query.inputName, "(")
688+
writer.write(line: "try await execute(", query.inputName, "(")
689689
initInput()
690690
writer.write("))")
691691
}
@@ -697,7 +697,7 @@ public struct SwiftLanguage: Language {
697697
writer.write(", tx: borrowing Transaction) throws -> Output ")
698698

699699
writer.braces {
700-
writer.write(line: "try execute(with: ", query.inputName, "(")
700+
writer.write(line: "try execute(", query.inputName, "(")
701701
initInput()
702702
writer.write("), tx: tx)")
703703
}
@@ -706,10 +706,10 @@ public struct SwiftLanguage: Language {
706706
writer.blankLine()
707707
writer.write(line: "func observe(")
708708
writeInput()
709-
writer.write(") -> any QueryObservation<Output> ")
709+
writer.write(") -> QueryStream<Output> ")
710710

711711
writer.braces {
712-
writer.write(line: "observe(with: ", query.inputName, "(")
712+
writer.write(line: "observe(", query.inputName, "(")
713713
initInput()
714714
writer.write("))")
715715
}

Sources/Otter/Database.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,30 @@ public extension Database {
6969

7070

7171
extension Database where Adapters == DefaultAdapters {
72+
/// Opens a connection pool to the database at the given URL.
73+
///
74+
/// - Parameter url: The url of the database file
75+
init(url: URL) throws {
76+
self = try Self(url: url, adapters: DefaultAdapters())
77+
}
78+
79+
/// Opens a connection pool to the database at the given path.
80+
///
81+
/// - Parameter path: The path of the database file
82+
init(path: String) throws {
83+
self = try Self(path: path, adapters: DefaultAdapters())
84+
}
85+
86+
/// Opens a connection pool to the database
87+
///
88+
/// - Parameter config: The configuration specifying any info
89+
/// needed to open the database.
90+
init(config: DatabaseConfig) throws {
91+
self = try Self(config: config, adapters: DefaultAdapters())
92+
}
93+
7294
/// Creates an in memory database.
73-
static func inMemory() throws -> Self {
95+
public static func inMemory() throws -> Self {
7496
return try Self(config: DatabaseConfig(path: nil), adapters: DefaultAdapters())
7597
}
7698
}

Sources/Otter/Queries/AnyQuery.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ public struct AnyQuery<Input: Sendable, Output: Sendable>: Query {
3535
transactionKind: query.transactionKind,
3636
connection: query.connection,
3737
watchedTables: query.watchedTables,
38-
execute: { try query.execute(with: $0, tx: $1) },
39-
observe: { query.observation(with: $0) }
38+
execute: { try query.execute($0, tx: $1) },
39+
observe: { query.observation($0) }
4040
)
4141
}
4242

43-
public func execute(with input: Input, tx: borrowing Transaction) throws -> Output {
43+
public func execute(_ input: Input, tx: borrowing Transaction) throws -> Output {
4444
try _execute(input, tx)
4545
}
4646

47-
public func observation(with input: Input) -> any QueryObservation<Output> {
47+
public func observation(_ input: Input) -> any QueryObservation<Output> {
4848
_observe(input)
4949
}
5050
}

0 commit comments

Comments
 (0)