Skip to content

Commit 701e672

Browse files
committed
Update readme
1 parent 13dbce9 commit 701e672

3 files changed

Lines changed: 24 additions & 13 deletions

File tree

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,21 @@ Otter supports Swift Package Manager. To install add the following to your `Pack
129129
let package = Package(
130130
[...]
131131
dependencies: [
132-
.Package(url: "https://github.com/wickwirew/Otter.git", from: "...")
132+
.package(url: "https://github.com/wickwirew/Otter.git", from: "...")
133+
],
134+
targets: [
135+
.target(
136+
name: "MyProject",
137+
dependencies: ["Otter"],
138+
// ⚠️ Plugin is optional, can just use the CLI if desired
139+
plugins: [.plugin(name: "OtterPlugin", package: "Otter")]
140+
),
133141
]
134142
)
135143
```
136144

137-
Also the cli tool will be needed to be installed.
145+
## Install CLI tool
146+
You can install the CLI tool via homebrew by executing:
138147
```
139148
brew tap wickwirew/wickwirew
140149
brew install otter
@@ -150,20 +159,23 @@ This will create an `otter.yaml` configuration file. Here is where you can setup
150159
> [!TIP]
151160
> Follow the SQL standard and use singular table names. This will stop table structs from being named plural
152161
153-
#### Generating the Database
154-
Once you have your first migration in and the project setup you can now generate the database. In the same directory where `init` was run, you run the `gen` command.
162+
### Adding a New Migration
163+
When a new migration is needed, you can simply add a new file with a number 1 higher than the previous. To automatically do this the cli tool can do it for you by running
155164
```
156-
otter gen --output Queries.swift
165+
otter migrations add
157166
```
158167

159-
This will compile and check all migrations and queries, then generate all Swift required to talk to the database.
168+
> [!WARNING]
169+
> Plugin requires a clean build any time a new `sql` file is added so the input file list can be updated.
160170
161-
### Adding a New Migration
162-
When a new migration is needed, you can simply add a new file with a number 1 higher than the previous. To automatically do this the cli tool can do it for you by running
171+
#### Generating the Database - Without Plugin
172+
Once you have your first migration in and the project setup you can now generate the database. In the same directory where `init` was run, you run the `gen` command.
163173
```
164-
otter migrations add
174+
otter generate
165175
```
166176

177+
This will compile and check all migrations and queries, then generate all Swift required to talk to the database.
178+
167179
# Opening a Connection
168180
Once you have your database being generated, you can now open a connection to it. Each database will automatically have a few initializers at hand to choose from. Each are listed below. When the connection is opened, all migrations are run instantly.
169181

@@ -188,7 +200,7 @@ let database = try DB(config: config)
188200
# Queries
189201
All queries will be stored in the `/Queries` directory. More than one query can go in each file. To get started, create a new file in the `/Queries` directory. The cli can do this automatically. In the same directory where `init` was run, execute
190202
```
191-
otter queries add --name <some-name>
203+
otter queries add <some-name>
192204
```
193205

194206
Open the file that was created in `/Queries`, it should be blank. Individual queries can be defined using the the following format. At the moment a single query can only have one statement.

Sources/Compiler/Gen/Language.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public struct GenerationOptions: Sendable {
329329
public init(
330330
databaseName: String,
331331
imports: [String] = [],
332-
createDirectoryIfNeeded: Bool
332+
createDirectoryIfNeeded: Bool = true
333333
) {
334334
self.databaseName = databaseName
335335
self.imports = imports

Sources/OtterMacros/DatabaseMacro.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ extension DatabaseMacro: MemberMacro {
6565

6666
let swift = SwiftLanguage(
6767
options: GenerationOptions(
68-
databaseName: "",
69-
createDirectoryIfNeeded: false
68+
databaseName: ""
7069
)
7170
)
7271

0 commit comments

Comments
 (0)