MCPcopy Create free account
hub / github.com/zenstackhq/zenstack / getFieldAttributes

Function getFieldAttributes

packages/cli/src/actions/pull/provider/mysql.ts:287–318  ·  view source on GitHub ↗
({ fieldName, fieldType, datatype, length, precision, services })

Source from the content-addressed store, hash-verified

285 },
286
287 getFieldAttributes({ fieldName, fieldType, datatype, length, precision, services }) {
288 const factories: DataFieldAttributeFactory[] = [];
289
290 // Add @updatedAt for DateTime fields named updatedAt or updated_at
291 if (fieldType === 'DateTime' && (fieldName.toLowerCase() === 'updatedat' || fieldName.toLowerCase() === 'updated_at')) {
292 factories.push(new DataFieldAttributeFactory().setDecl(getAttributeRef('@updatedAt', services)));
293 }
294
295 // Add @db.* attribute if the datatype differs from the default
296 const dbAttr = services.shared.workspace.IndexManager.allElements('Attribute').find(
297 (d) => d.name.toLowerCase() === `@db.${datatype.toLowerCase()}`,
298 )?.node as Attribute | undefined;
299
300 const defaultDatabaseType = this.getDefaultDatabaseType(fieldType as BuiltinType);
301
302 if (
303 dbAttr &&
304 defaultDatabaseType &&
305 (defaultDatabaseType.type !== datatype ||
306 (defaultDatabaseType.precision &&
307 defaultDatabaseType.precision !== (length ?? precision)))
308 ) {
309 const dbAttrFactory = new DataFieldAttributeFactory().setDecl(dbAttr);
310 const sizeValue = length ?? precision;
311 if (sizeValue !== undefined && sizeValue !== null) {
312 dbAttrFactory.addArg((a) => a.NumberLiteral.setValue(sizeValue));
313 }
314 factories.push(dbAttrFactory);
315 }
316
317 return factories;
318 },
319};
320
321function getTableIntrospectionQuery() {

Callers

nothing calls this directly

Calls 7

getAttributeRefFunction · 0.90
pushMethod · 0.80
findMethod · 0.80
setDeclMethod · 0.45
addArgMethod · 0.45
setValueMethod · 0.45

Tested by

no test coverage detected