(name: string, options: FieldArgs)
| 177 | } |
| 178 | |
| 179 | constructor(name: string, options: FieldArgs) { |
| 180 | if (!name) throw new MissingFieldNameError("[PrismaField]: A field name is required") |
| 181 | if (!options.type) { |
| 182 | console.warn(`No field type specified for field ${name}, falling back to "String".`) |
| 183 | options.type = FieldType.String |
| 184 | } |
| 185 | this.name = name |
| 186 | this.isList = fallbackIfUndef(false, options.isList) |
| 187 | this.isRequired = fallbackIfUndef(true, options.isRequired) |
| 188 | this.isUnique = fallbackIfUndef(false, options.isUnique) |
| 189 | this.isId = fallbackIfUndef(false, options.isId) |
| 190 | this.type = options.type |
| 191 | this.default = options.default |
| 192 | this.isUpdatedAt = fallbackIfUndef(false, options.isUpdatedAt) |
| 193 | this.relationFromFields = options.relationFromFields |
| 194 | this.relationToFields = options.relationToFields |
| 195 | if (!this.isRequired && this.isList) { |
| 196 | throw new Error("[PrismaField]: a type cannot be both optional and a list") |
| 197 | } |
| 198 | if (this.isId && this.default === undefined) { |
| 199 | throw new Error("[PrismaField]: ID fields must have a default value") |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | appendTo(model: ast.Model) { |
| 204 | if (model.properties.some((prop) => prop.type === "field" && prop.name === this.name)) return |
nothing calls this directly
no test coverage detected