{"size": 749, "ext": "js", "max_stars_repo_path": "packages/dbml-core/src/parse/mssql/column_definition/actions.js", "max_stars_repo_name": "softwaretechnik-berlin/dbml", "max_stars_repo_stars_event_min_datetime": "2019-05-16T11:05:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T21:17:29.000Z", "max_issues_repo_path": "packages/dbml-core/src/parse/mssql/column_definition/actions.js", "max_issues_repo_name": "softwaretechnik-berlin/dbml", "max_issues_repo_issues_event_min_datetime": "2019-05-18T08:23:47.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T17:09:37.000Z", "max_forks_repo_path": "packages/dbml-core/src/parse/mssql/column_definition/actions.js", "max_forks_repo_name": "softwaretechnik-berlin/dbml", "max_forks_repo_forks_event_min_datetime": "2019-05-22T14:09:25.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-26T11:39:01.000Z"}
{"max_stars_count": 1295, "max_issues_count": 181, "max_forks_count": 112, "avg_line_length": 22.696969697, "max_line_length": 87, "alphanum_fraction": 0.6261682243}
const _ = require('lodash');

function makeDataType (typeName, args) {
  const argsString = args ? args.join(',') : null;
  return {
    type: 'type',
    value: {
      type_name: !argsString ? _.last(typeName) : `${_.last(typeName)}(${argsString})`,
      schemaName: typeName.length > 1 ? typeName[0] : null,
      args: argsString,
    },
  };
}

function makeColumn (fieldName, dataType, fieldSettings) {
  const value = {};
  value[dataType.type] = dataType.value;
  fieldSettings.forEach(setting => {
    if (setting) value[setting.type] = setting.value;
  });
  value.name = fieldName[0];
  if (!value.inline_refs) value.inline_refs = [];
  return {
    type: 'fields',
    value,
  };
}

module.exports = {
  makeColumn,
  makeDataType,
};
