Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate camel caseing options #105

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/schemats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface SchematsConfig {
table: string[] | string,
schema: string,
output: string,
camelCase: boolean,
camelCase: boolean | 'columns' | 'types',
noHeader: boolean,
}

Expand All @@ -39,7 +39,8 @@ let argv: SchematsConfig = yargs
.nargs('s', 1)
.describe('s', 'schema name')
.alias('C', 'camelCase')
.describe('C', 'Camel-case columns')
.choices('C', [undefined, true, 'columns', 'types'])
.describe('C', 'Camel-case columns and types')
.describe('noHeader', 'Do not write header')
.demand('o')
.nargs('o', 1)
Expand Down
6 changes: 3 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const DEFAULT_OPTIONS: OptionValues = {
}

export type OptionValues = {
camelCase?: boolean
camelCase?: boolean | 'columns' | 'types',
writeHeader?: boolean // write schemats description header
}

Expand All @@ -18,10 +18,10 @@ export default class Options {
}

transformTypeName (typename: string) {
return this.options.camelCase ? upperFirst(camelCase(typename)) : typename
return this.options.camelCase === true || this.options.camelCase === 'types' ? upperFirst(camelCase(typename)) : typename
}

transformColumnName (columnName: string) {
return this.options.camelCase ? camelCase(columnName) : columnName
return this.options.camelCase === true || this.options.camelCase === 'columns' ? camelCase(columnName) : columnName
}
}
134 changes: 134 additions & 0 deletions test/expected/postgres/osm-camelcase-columns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/* tslint:disable */

export type FormatEnum = 'html' | 'markdown' | 'text';
export type UserStatusEnum = 'active' | 'confirmed' | 'deleted' | 'pending' | 'suspended';

export namespace usersFields {
export type email = string;
export type id = number;
export type passCrypt = string;
export type creationTime = Date;
export type displayName = string;
export type dataPublic = boolean;
export type description = string;
export type homeLat = number | null;
export type homeLon = number | null;
export type homeZoom = number | null;
export type nearby = number | null;
export type passSalt = string | null;
export type imageFileName = string | null;
export type emailValid = boolean;
export type newEmail = string | null;
export type creationIp = string | null;
export type languages = string | null;
export type status = UserStatusEnum;
export type termsAgreed = Date | null;
export type considerPd = boolean;
export type preferredEditor = string | null;
export type termsSeen = boolean;
export type authUid = string | null;
export type descriptionFormat = FormatEnum;
export type imageFingerprint = string | null;
export type changesetsCount = number;
export type tracesCount = number;
export type diaryEntriesCount = number;
export type imageUseGravatar = boolean;
export type imageContentType = string | null;
export type authProvider = string | null;
export type uuidColumn = string | null;
export type number_ = number | null;
export type string_ = string | null;
export type moneyCol = number | null;
export type charCol = string | null;
export type timeCol = string | null;
export type inetCol = string | null;
export type jsonbCol = Object | null;
export type numericCol = number | null;
export type byteaCol = string | null;
export type boolArrayCol = Array<boolean> | null;
export type varcharArrayCol = Array<string> | null;
export type int2ArrayCol = Array<number> | null;
export type int4ArrayCol = Array<number> | null;
export type int8ArrayCol = Array<number> | null;
export type uuidArrayCol = Array<string> | null;
export type textArrayCol = Array<string> | null;
export type byteaArrayCol = Array<string> | null;
export type realCol = number | null;
export type doubleCol = number | null;
export type timeWithTz = string | null;
export type oidCol = number | null;
export type intervalCol = string | null;
export type jsonCol = Object | null;
export type dateCol = Date | null;
export type unspportedPathType = any | null;
export type nameTypeCol = string | null;
export type jsonArrayCol = Array<Object> | null;
export type jsonbArrayCol = Array<Object> | null;
export type timestamptzArrayCol = Array<Date> | null;

}

export interface Users {
email: usersFields.email;
id: usersFields.id;
passCrypt: usersFields.passCrypt;
creationTime: usersFields.creationTime;
displayName: usersFields.displayName;
dataPublic: usersFields.dataPublic;
description: usersFields.description;
homeLat: usersFields.homeLat;
homeLon: usersFields.homeLon;
homeZoom: usersFields.homeZoom;
nearby: usersFields.nearby;
passSalt: usersFields.passSalt;
imageFileName: usersFields.imageFileName;
emailValid: usersFields.emailValid;
newEmail: usersFields.newEmail;
creationIp: usersFields.creationIp;
languages: usersFields.languages;
status: usersFields.status;
termsAgreed: usersFields.termsAgreed;
considerPd: usersFields.considerPd;
preferredEditor: usersFields.preferredEditor;
termsSeen: usersFields.termsSeen;
authUid: usersFields.authUid;
descriptionFormat: usersFields.descriptionFormat;
imageFingerprint: usersFields.imageFingerprint;
changesetsCount: usersFields.changesetsCount;
tracesCount: usersFields.tracesCount;
diaryEntriesCount: usersFields.diaryEntriesCount;
imageUseGravatar: usersFields.imageUseGravatar;
imageContentType: usersFields.imageContentType;
authProvider: usersFields.authProvider;
uuidColumn: usersFields.uuidColumn;
number: usersFields.number_;
string: usersFields.string_;
moneyCol: usersFields.moneyCol;
charCol: usersFields.charCol;
timeCol: usersFields.timeCol;
inetCol: usersFields.inetCol;
jsonbCol: usersFields.jsonbCol;
numericCol: usersFields.numericCol;
byteaCol: usersFields.byteaCol;
boolArrayCol: usersFields.boolArrayCol;
varcharArrayCol: usersFields.varcharArrayCol;
int2ArrayCol: usersFields.int2ArrayCol;
int4ArrayCol: usersFields.int4ArrayCol;
int8ArrayCol: usersFields.int8ArrayCol;
uuidArrayCol: usersFields.uuidArrayCol;
textArrayCol: usersFields.textArrayCol;
byteaArrayCol: usersFields.byteaArrayCol;
realCol: usersFields.realCol;
doubleCol: usersFields.doubleCol;
timeWithTz: usersFields.timeWithTz;
oidCol: usersFields.oidCol;
intervalCol: usersFields.intervalCol;
jsonCol: usersFields.jsonCol;
dateCol: usersFields.dateCol;
unspportedPathType: usersFields.unspportedPathType;
nameTypeCol: usersFields.nameTypeCol;
jsonArrayCol: usersFields.jsonArrayCol;
jsonbArrayCol: usersFields.jsonbArrayCol;
timestamptzArrayCol: usersFields.timestamptzArrayCol;

}
133 changes: 133 additions & 0 deletions test/expected/postgres/osm-camelcase-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/* tslint:disable */

export type format_enum = 'html' | 'markdown' | 'text';
export type user_status_enum = 'active' | 'confirmed' | 'deleted' | 'pending' | 'suspended';

export namespace UsersFields {
export type email = string;
export type id = number;
export type pass_crypt = string;
export type creation_time = Date;
export type display_name = string;
export type data_public = boolean;
export type description = string;
export type home_lat = number | null;
export type home_lon = number | null;
export type home_zoom = number | null;
export type nearby = number | null;
export type pass_salt = string | null;
export type image_file_name = string | null;
export type email_valid = boolean;
export type new_email = string | null;
export type creation_ip = string | null;
export type languages = string | null;
export type status = user_status_enum;
export type terms_agreed = Date | null;
export type consider_pd = boolean;
export type preferred_editor = string | null;
export type terms_seen = boolean;
export type auth_uid = string | null;
export type description_format = format_enum;
export type image_fingerprint = string | null;
export type changesets_count = number;
export type traces_count = number;
export type diary_entries_count = number;
export type image_use_gravatar = boolean;
export type image_content_type = string | null;
export type auth_provider = string | null;
export type uuid_column = string | null;
export type number_ = number | null;
export type string_ = string | null;
export type money_col = number | null;
export type char_col = string | null;
export type time_col = string | null;
export type inet_col = string | null;
export type jsonb_col = Object | null;
export type numeric_col = number | null;
export type bytea_col = string | null;
export type bool_array_col = Array<boolean> | null;
export type varchar_array_col = Array<string> | null;
export type int2_array_col = Array<number> | null;
export type int4_array_col = Array<number> | null;
export type int8_array_col = Array<number> | null;
export type uuid_array_col = Array<string> | null;
export type text_array_col = Array<string> | null;
export type bytea_array_col = Array<string> | null;
export type real_col = number | null;
export type double_col = number | null;
export type time_with_tz = string | null;
export type oid_col = number | null;
export type interval_col = string | null;
export type json_col = Object | null;
export type date_col = Date | null;
export type unspported_path_type = any | null;
export type name_type_col = string | null;
export type json_array_col = Array<Object> | null;
export type jsonb_array_col = Array<Object> | null;
export type timestamptz_array_col = Array<Date> | null;

}

export interface users {
email: UsersFields.email;
id: UsersFields.id;
pass_crypt: UsersFields.pass_crypt;
creation_time: UsersFields.creation_time;
display_name: UsersFields.display_name;
data_public: UsersFields.data_public;
description: UsersFields.description;
home_lat: UsersFields.home_lat;
home_lon: UsersFields.home_lon;
home_zoom: UsersFields.home_zoom;
nearby: UsersFields.nearby;
pass_salt: UsersFields.pass_salt;
image_file_name: UsersFields.image_file_name;
email_valid: UsersFields.email_valid;
new_email: UsersFields.new_email;
creation_ip: UsersFields.creation_ip;
languages: UsersFields.languages;
status: UsersFields.status;
terms_agreed: UsersFields.terms_agreed;
consider_pd: UsersFields.consider_pd;
preferred_editor: UsersFields.preferred_editor;
terms_seen: UsersFields.terms_seen;
auth_uid: UsersFields.auth_uid;
description_format: UsersFields.description_format;
image_fingerprint: UsersFields.image_fingerprint;
changesets_count: UsersFields.changesets_count;
traces_count: UsersFields.traces_count;
diary_entries_count: UsersFields.diary_entries_count;
image_use_gravatar: UsersFields.image_use_gravatar;
image_content_type: UsersFields.image_content_type;
auth_provider: UsersFields.auth_provider;
uuid_column: UsersFields.uuid_column;
number: UsersFields.number_;
string: UsersFields.string_;
money_col: UsersFields.money_col;
char_col: UsersFields.char_col;
time_col: UsersFields.time_col;
inet_col: UsersFields.inet_col;
jsonb_col: UsersFields.jsonb_col;
numeric_col: UsersFields.numeric_col;
bytea_col: UsersFields.bytea_col;
bool_array_col: UsersFields.bool_array_col;
varchar_array_col: UsersFields.varchar_array_col;
int2_array_col: UsersFields.int2_array_col;
int4_array_col: UsersFields.int4_array_col;
int8_array_col: UsersFields.int8_array_col;
uuid_array_col: UsersFields.uuid_array_col;
text_array_col: UsersFields.text_array_col;
bytea_array_col: UsersFields.bytea_array_col;
real_col: UsersFields.real_col;
double_col: UsersFields.double_col;
time_with_tz: UsersFields.time_with_tz;
oid_col: UsersFields.oid_col;
interval_col: UsersFields.interval_col;
json_col: UsersFields.json_col;
date_col: UsersFields.date_col;
unspported_path_type: UsersFields.unspported_path_type;
name_type_col: UsersFields.name_type_col;
json_array_col: UsersFields.json_array_col;
jsonb_array_col: UsersFields.jsonb_array_col;
timestamptz_array_col: UsersFields.timestamptz_array_col;
}
6 changes: 6 additions & 0 deletions test/fixture/postgres/osm-camelcase-columns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tables": ["users"],
"schema": null,
"camelCaseColumns": "columns",
"writeHeader": false
}
6 changes: 6 additions & 0 deletions test/fixture/postgres/osm-camelcase-types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tables": ["users"],
"schema": null,
"camelCase": "types",
"writeHeader": false
}
4 changes: 2 additions & 2 deletions test/integration/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('schemats cli tool integration testing', () => {
it('should run without error', () => {
let {status, stdout, stderr} = spawnSync('node', [
'bin/schemats', 'generate',
'-c', process.env.POSTGRES_URL,
'-c', process.env.POSTGRES_URL as string,
'-o', '/tmp/schemats_cli_postgres.ts'
], { encoding: 'utf-8' })
console.log('opopopopop', stdout, stderr)
Expand All @@ -27,7 +27,7 @@ describe('schemats cli tool integration testing', () => {
it('should run without error', () => {
let {status} = spawnSync('node', [
'bin/schemats', 'generate',
'-c', process.env.MYSQL_URL,
'-c', process.env.MYSQL_URL as string,
'-s', 'test',
'-o', '/tmp/schemats_cli_postgres.ts'
])
Expand Down
16 changes: 16 additions & 0 deletions test/integration/schematGeneration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ describe('schemat generation integration testing', () => {
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Camelcase (types only) generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm-camelcase-types.ts'
const expectedFile = './test/expected/postgres/osm-camelcase-types.ts'
const config: any = './fixture/postgres/osm-camelcase-types.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Camelcase (columns only) generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm-camelcase-columns.ts'
const expectedFile = './test/expected/postgres/osm-camelcase-columns.ts'
const config: any = './fixture/postgres/osm-camelcase-columns.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
})

describe('mysql', () => {
Expand Down