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

Function getDefaultValue

packages/cli/src/actions/pull/provider/sqlite.ts:361–406  ·  view source on GitHub ↗
({ defaultValue, fieldType, services, enums })

Source from the content-addressed store, hash-verified

359 },
360
361 getDefaultValue({ defaultValue, fieldType, services, enums }) { // datatype and datatype_name not used for SQLite
362 const val = defaultValue.trim();
363
364 switch (fieldType) {
365 case 'DateTime':
366 if (val === 'CURRENT_TIMESTAMP' || val === 'now()') {
367 return (ab) => ab.InvocationExpr.setFunction(getFunctionRef('now', services));
368 }
369 // Fallback to string literal for other DateTime defaults
370 return (ab) => ab.StringLiteral.setValue(val);
371
372 case 'Int':
373 case 'BigInt':
374 if (val === 'autoincrement') {
375 return (ab) => ab.InvocationExpr.setFunction(getFunctionRef('autoincrement', services));
376 }
377 return (ab) => ab.NumberLiteral.setValue(val);
378
379 case 'Float':
380 return normalizeFloatDefault(val);
381
382 case 'Decimal':
383 return normalizeDecimalDefault(val);
384
385 case 'Boolean':
386 return (ab) => ab.BooleanLiteral.setValue(val === 'true' || val === '1');
387 case 'String':
388 if (val.startsWith("'") && val.endsWith("'")) {
389 const strippedName = val.slice(1, -1);
390 const enumDef = enums.find((e) => e.fields.find((v) => getDbName(v) === strippedName));
391 if (enumDef) {
392 const enumField = enumDef.fields.find((v) => getDbName(v) === strippedName);
393 if (enumField) return (ab) => ab.ReferenceExpr.setTarget(enumField);
394 }
395 return (ab) => ab.StringLiteral.setValue(strippedName);
396 }
397 return (ab) => ab.StringLiteral.setValue(val);
398 case 'Json':
399 return (ab) => ab.StringLiteral.setValue(val);
400 case 'Bytes':
401 return (ab) => ab.StringLiteral.setValue(val);
402 }
403
404 console.warn(`Unsupported default value type: "${defaultValue}" for field type "${fieldType}". Skipping default value.`);
405 return null;
406 },
407
408 getFieldAttributes({ fieldName, fieldType, services }) {
409 const factories: DataFieldAttributeFactory[] = [];

Callers

nothing calls this directly

Calls 8

getFunctionRefFunction · 0.90
normalizeFloatDefaultFunction · 0.90
normalizeDecimalDefaultFunction · 0.90
getDbNameFunction · 0.90
setFunctionMethod · 0.80
findMethod · 0.80
setTargetMethod · 0.80
setValueMethod · 0.45

Tested by

no test coverage detected