- 
                Notifications
    You must be signed in to change notification settings 
- Fork 14
Services
Provides easy access to some commonly used services in Alchemy.
These services are Injected from the global Container. You
can add your own services in extensions if you'd like.
public enum ServicesServices.db
// equivalant to
Container.global.resolve(Database.self)
// equivalent to
@Inject
var db: DatabaseThe main database of your app. By default, this isn't
registered, so don't forget to do so in your
Application.setup!
var db: Databasestruct MyServer: Application {
    func setup() {
        Services.db = PostgresDatabase(
            DatabaseConfig(
                socket: .ip(host: "localhost", port: 5432),
                database: "alchemy",
                username: "admin",
                password: "password"
            )
        )
    }
}
// Now, `Services.db` is usable elsewhere.
Services.db // `PostgresDatabase(...)` registered above
    .runRawQuery("select * from users;")
    .whenSuccess { rows in
        print("Got \(rows.count) results!")
    }The router to which all incoming requests in your application are routed.
var router: RouterA scheduler for scheduling recurring tasks.
var scheduler: SchedulerAn HTTPClient for making HTTP requests.
var client: HTTPClientUsage:
Services.client
    .get(url: "https://swift.org")
    .whenComplete { result in
        switch result {
        case .failure(let error):
            ...
        case .success(let response):
            ...
        }
    }The current EventLoop.
var eventLoop: EventLoopThe EventLoopGroup of this application.
var eventLoopGroup: EventLoopGroupA NIOThreadPool for running expensive/blocking work on.
var threadPool: NIOThreadPoolBy default, this pool has a number of threads equal to the number of logical cores on this machine. This pool is created and started when first accessed.
A ServiceLifecycle hooking into this application's
lifecycle.
var lifecycle: ServiceLifecycleMocks many common services. Can be called in the setUp()
function of test cases.
public static func mock()Generated at 2021-01-13T22:24:59-0800 using swift-doc 1.0.0-beta.5.
Alchemy
Types
- AlterTableBuilder
- BCryptDigest
- BasicAuthMiddleware
- BcryptError
- BelongsToRelationship
- CORSMiddleware
- CORSMiddleware.AllowOriginSetting
- CORSMiddleware.Configuration
- ColumnType
- CreateColumn
- CreateColumnBuilder
- CreateIndex
- CreateTableBuilder
- DatabaseConfig
- DatabaseError
- DatabaseField
- DatabaseKeyMappingStrategy
- DatabaseValue
- DayUnit
- Env
- FrequencyTyped
- Grammar
- HTTPAuth
- HTTPAuth.Basic
- HTTPAuth.Bearer
- HTTPBody
- HTTPError
- HasManyRelationship
- HasOneRelationship
- HasRelationship
- HourUnit
- JoinClause
- JoinType
- Launch
- Log
- MIMEType
- MinuteUnit
- ModelQuery
- MySQLDatabase
- Operator
- OrderClause
- OrderClause.Sort
- OrderedDictionary
- PapyrusClientError
- PathParameter
- PathParameter.DecodingError
- PostgresDatabase
- Query
- Request
- Response
- Router
- RuneError
- SQL
- SQLJSON
- Scheduler
- Schema
- SecondUnit
- Services
- Socket
- StaticFileMiddleware
- StringLength
- Thread
- TokenAuthMiddleware
- WeekUnit
- Weekday
- WhereBoolean
- WhereColumn
- WhereIn
- WhereIn.InType
- WhereNested
- WhereRaw
- WhereValue