-
Couldn't load subscription status.
- Fork 14
Model
An ActiveRecord-esque type used for modeling a table in a relational database. Contains many extensions for making database queries, supporting relationships & much more.
public protocol Model: Identifiable, ModelMaybeOptionalIdentifiable, ModelMaybeOptional
The identifier / primary key of this type.
var id: Self.Identifier?The table with which this object is associated. Defaults to
String(describing: Self.self) aka the name of the type. Can
be overridden for custom table names.
var tableName: Stringstruct User: Model {
static var tableName: String = "my_user_table"
var id: Int?
let name: String
let email: String
}How should the Swift CodingKeys be mapped to database
columns? Defaults to .convertToSnakeCase. Can be
overridden on a per-type basis.
var keyMappingStrategy: DatabaseKeyMappingStrategyWhen mapping a Model to an SQL table, @BelongsTo
properties will have their property names suffixed by this
String. Defaults to Id. This value is affected by
keyMappingStrategy, so if the keyMappingStrategy of the
database is .convertToSnakeCase, the default suffix will
effectively be _id.
var belongsToColumnSuffix: StringUsage:
struct User: Model {
...
@BelongsTo
var parent: User // will map to column `parentId` of type
// `User.ID`.
}The JSONDecoder to use when decoding any JSON fields of this
type. A JSON field is any Codable field that doesn't have a
corresponding DatabaseValue.
var jsonDecoder: JSONDecoderDefaults to JSONDecoder().
The JSONEncoder to use when decoding any JSON fields of this
type. A JSON field is any Codable field on this type that
doesn't have a corresponding DatabaseValue.
var jsonEncoder: JSONEncoderDefaults to JSONEncoder().
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