|
1 | | -//extension SchemaBuilder { |
2 | | -// public func field<T>(for keyPath: KeyPath<Model, T>, type: PostgreSQLColumnType, primaryKey: Bool? = nil, generatedByDefaultAsIdentity: Bool = false, notNull: Bool = true, default: String? = nil) { |
3 | | -// var attributes: [String] = [] |
4 | | -// if let primaryKey = primaryKey { |
5 | | -// if primaryKey { |
6 | | -// attributes.append("PRIMARY KEY") |
7 | | -// } |
8 | | -// } else if keyPath == Model.idKey { |
9 | | -// attributes.append("PRIMARY KEY") |
10 | | -// } |
11 | | -// if generatedByDefaultAsIdentity { |
12 | | -// attributes.append("GENERATED BY DEFAULT AS IDENTITY") |
13 | | -// } |
14 | | -// if notNull { |
15 | | -// attributes.append("NOT NULL") |
16 | | -// } |
17 | | -// if let `default` = `default` { |
18 | | -// attributes.append("DEFAULT " + `default`) |
19 | | -// } |
20 | | -// field(for: .fluentProperty(.keyPath(keyPath)), type: .init(name: type.name, parameters: type.parameters, attributes: attributes)) |
21 | | -// } |
22 | | -//} |
| 1 | +extension SchemaBuilder where Model.Database == PostgreSQLDatabase { |
| 2 | + public func field<T>( |
| 3 | + for keyPath: KeyPath<Model, T>, |
| 4 | + type dataType: PostgreSQLQuery.DataType, |
| 5 | + isArray: Bool = false, |
| 6 | + collate: String? = nil, |
| 7 | + _ constraints: PostgreSQLQuery.ColumnConstraint... |
| 8 | + ) { |
| 9 | + let property = FluentProperty.keyPath(keyPath) |
| 10 | + let columnDefinition = PostgreSQLQuery.ColumnDefinition.init( |
| 11 | + name: property.path[0], |
| 12 | + dataType: dataType, |
| 13 | + isArray: isArray, |
| 14 | + collate: collate, |
| 15 | + constraints: constraints |
| 16 | + ) |
| 17 | + schema.createColumns.append(columnDefinition) |
| 18 | + } |
| 19 | +} |
0 commit comments