mirror of https://github.com/vapor/docs.git
dbkit fixmes
This commit is contained in:
parent
2750a4759d
commit
eae63f6422
|
|
@ -6,7 +6,7 @@ Many of Vapor's packages such as the Fluent drivers, Redis, and Vapor core are b
|
|||
|
||||
## Config
|
||||
|
||||
Your first interaction with Database Kit will most likely be with the [`DatabasesConfig`](#fixme) struct. This type helps you configure one or more databases to your application and will ultimately yield a [`Databases`](#fixme) struct. This usually takes place in [`configure.swift`](../getting-started/structure/#configureswift).
|
||||
Your first interaction with Database Kit will most likely be with the [`DatabasesConfig`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabasesConfig.html) struct. This type helps you configure one or more databases to your application and will ultimately yield a [`Databases`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/Databases.html) struct. This usually takes place in [`configure.swift`](../getting-started/structure/#configureswift).
|
||||
|
||||
```swift
|
||||
// Create a SQLite database.
|
||||
|
|
@ -24,7 +24,7 @@ dbsConfig.add(sqliteDB, as: .sqlite)
|
|||
services.register(dbsConfig)
|
||||
```
|
||||
|
||||
Using the [`add(...)`](#fixme) methods, you can register [`Database`](#fixme)s to the config. You can register instances of a database, a database type, or a closure that creates a database. The latter two methods will be resolved when your container boots.
|
||||
Using the [`add(...)`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabasesConfig.html) methods, you can register [`Database`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Protocols/Database.html)s to the config. You can register instances of a database, a database type, or a closure that creates a database. The latter two methods will be resolved when your container boots.
|
||||
|
||||
You can also configure options on your databases, such as enabling logging.
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ See the section on [logging](#logging) for more information.
|
|||
|
||||
### Identifier
|
||||
|
||||
Most database integrations will provide a default [`DatabaseIdentifier`](#fixme) to use. However, you can always create your own. This is usually done by creating a static extension.
|
||||
Most database integrations will provide a default [`DatabaseIdentifier`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabaseIdentifier.html) to use. However, you can always create your own. This is usually done by creating a static extension.
|
||||
|
||||
```swift
|
||||
extension DatabaseIdentifier {
|
||||
|
|
@ -52,7 +52,7 @@ extension DatabaseIdentifier {
|
|||
|
||||
### Databases
|
||||
|
||||
Once you have registered a `DatabasesConfig` to your services and booted a container, you can take advantage of the convenience extensions on [`Container`](#fixme) to start creating connections.
|
||||
Once you have registered a `DatabasesConfig` to your services and booted a container, you can take advantage of the convenience extensions on [`Container`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Extensions/Container.html) to start creating connections.
|
||||
|
||||
```swift
|
||||
// Creates a new connection to `.sqlite` db
|
||||
|
|
@ -71,7 +71,7 @@ Database Kit's main focus is on creating, managing, and pooling connections. Cre
|
|||
|
||||
A common solution to connection management is the use of connection pools. These pools usually have a set maximum number of connections that are allowed to be open at once. Each time the pool is asked for a connection, it will first check if one is available before creating a new connection. If none are available, it will create a new one. If no connections are available and the pool is already at its maximum, the request for a new connection will _wait_ for a connection to be returned.
|
||||
|
||||
The easiest way to request and release a pooled connection is the method [`withPooledConnection(...)`](#fixme).
|
||||
The easiest way to request and release a pooled connection is the method [`withPooledConnection(...)`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Extensions/Container.html#/s:11DatabaseKit20withPooledConnectionXeXeF).
|
||||
|
||||
```swift
|
||||
// Requests a pooled connection to `.psql` db
|
||||
|
|
@ -92,7 +92,7 @@ let conn = try app.requestPooledConnection(to: .psql).wait()
|
|||
defer { app.releasePooledConnection(conn, to: .psql) }
|
||||
```
|
||||
|
||||
You can configure your connection pools using the [`DatabaseConnectionPoolConfig`](#fixme) struct.
|
||||
You can configure your connection pools using the [`DatabaseConnectionPoolConfig`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabaseConnectionPoolConfig.html) struct.
|
||||
|
||||
```swift
|
||||
// Create a new, empty pool config.
|
||||
|
|
@ -111,7 +111,7 @@ To prevent race conditions, pools are never shared between event loops. There is
|
|||
|
||||
You can always create a new connection to your databases if you need to. This will not affect your pooled connections. Creating new connections is especially useful during testing and app boot. But try not to do it in route closures since heavy traffic to your app could end up creating a lot of connections!
|
||||
|
||||
Similar to pooled connections, opening and closing new connections can be done using [`withNewConnection(...)`](#fixme).
|
||||
Similar to pooled connections, opening and closing new connections can be done using [`withNewConnection(...)`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Extensions/Container.html#/s:11DatabaseKit17withNewConnectionXeXeF).
|
||||
|
||||
```swift
|
||||
// Creates a new connection to `.sqlite` db
|
||||
|
|
@ -122,7 +122,7 @@ app.withNewConnection(to: .sqlite) { conn in
|
|||
|
||||
This method will create a new connection, calling the supplied closure when the connection is open. When the `Future` returned in the closure completes, the connection will be closed automatically.
|
||||
|
||||
You can also simply open a new connection with [`newConnection(...)`](#fixme).
|
||||
You can also simply open a new connection with [`newConnection(...)`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Extensions/Container.html#/s:11DatabaseKit13newConnectionXeXeF).
|
||||
|
||||
```swift
|
||||
// Creates a new connection to `.sqlite` db
|
||||
|
|
@ -134,7 +134,7 @@ defer { conn.close() }
|
|||
|
||||
## Logging
|
||||
|
||||
Databases can opt into supporting query logging via the [`LogSupporting`](#fixme) protocol. Databases that conform to this protocol can have loggers [configured](#config) via `DatabasesConfig`.
|
||||
Databases can opt into supporting query logging via the [`LogSupporting`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Protocols/LogSupporting.html) protocol. Databases that conform to this protocol can have loggers [configured](#config) via `DatabasesConfig`.
|
||||
|
||||
```swift
|
||||
// Enable logging on the SQLite database
|
||||
|
|
@ -151,15 +151,15 @@ let myLogger: DatabaseLogHandler = ...
|
|||
dbsConfig.enableLogging(for: .sqlite, logger: myLogger)
|
||||
```
|
||||
|
||||
Log handlers will receive an instance of [`DatabaseLog`](#fixme) for each logged query. This contains information such as the query, parameterized values, database id, and time.
|
||||
Log handlers will receive an instance of [`DatabaseLog`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Structs/DatabaseLog.html) for each logged query. This contains information such as the query, parameterized values, database id, and time.
|
||||
|
||||
## Keyed Cache
|
||||
|
||||
Databases can opt into supporting keyed-caching via the [`KeyedCacheSupporting`](#fixme) protocol. Databases that conform to this protocol can be used to create instances of [`DatabaseKeyedCache`](#fixme).
|
||||
Databases can opt into supporting keyed-caching via the [`KeyedCacheSupporting`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Protocols/KeyedCacheSupporting.html) protocol. Databases that conform to this protocol can be used to create instances of [`DatabaseKeyedCache`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Classes/DatabaseKeyedCache.html).
|
||||
|
||||
Keyed caches are capable of getting, setting, and removing `Codable` values at keys. They are sometimes called "key value stores".
|
||||
|
||||
To create a keyed cache, you can use the extensions on [`Container`](#fixme).
|
||||
To create a keyed cache, you can use the extensions on [`Container`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Extensions/Container.html#/s:11DatabaseKit10keyedCacheXeXeF).
|
||||
|
||||
```swift
|
||||
// Creates a DatabaseKeyedCache with .redis connection pool
|
||||
|
|
@ -176,7 +176,7 @@ print(world) // "world"
|
|||
try cache.remove("hello").wait()
|
||||
```
|
||||
|
||||
See the [`KeyedCache`](#fixme) protocol for more information.
|
||||
See the [`KeyedCache`](https://api.vapor.codes/database-kit/latest/DatabaseKit/Protocols/KeyedCache.html) protocol for more information.
|
||||
|
||||
## API Docs
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue