Template based scaffolding tool for PostgreSQL.
- Installation
- Synopsis
- Details
- API
- Classes
- Class: PgGenerator<O>
- Interfaces
- Interface: GeneratorOptions
- Modules
- Namespace: filterFunctions
Ƭ Context: object
Context provided to render function.
Name | Type |
---|---|
o |
Db | DbObject |
x |
Record<string, any> |
Defined in: types/index.ts:53
Ƭ Options: GeneratorOptions & ClientOptions
Defined in: types/index.ts:50
▸ generate(generator
: string, options?
: Options): Promise<void>
Executes the default sub-generator app
from a generator.
generate("generator-from-npm", options);
generate(require.resolve("./local-generator"), options);
Name | Type | Description |
---|---|---|
generator |
string | is the name or path of the generator. If it is a local path, use require.resolve or provide an absolute path. |
options? |
Options | are the options for the generator. |
Returns: Promise<void>
Defined in: generate.ts:15
▸ generate(generator
: string, subGenerator?
: string, options?
: Options): Promise<void>
Executes a sub-generator from a generator.
generate("generator-from-npm", "sub-generator");
generate(require.resolve("./local-generator"), "sub-generator", options);
Name | Type | Description |
---|---|---|
generator |
string | is the name or path of the generator. If it is a local path, use require.resolve or provide an absolute path. |
subGenerator? |
string | is the name of the generator. |
options? |
Options | are the new options added on top of curent options. |
Returns: Promise<void>
Defined in: generate.ts:27
pg-generator / PgGenerator
Base abstract class for for pg-generator classes.
Name | Type | Default |
---|---|---|
O |
GeneratorOptions | GeneratorOptions |
+ new PgGenerator<O>(options
: O, internalOptions
: InternalOptions): PgGenerator<O>
Creates an instance of PgGenerator.
Name | Type | Default |
---|---|---|
O |
GeneratorOptions | GeneratorOptions |
Name | Type | Description |
---|---|---|
options |
O | are parameters for several options. |
internalOptions |
InternalOptions | are added by pg-generator functions and not for user. |
Returns: PgGenerator<O>
Defined in: pg-generator.ts:23
▸ generate(): Promise<void>
Renders all templates in [rootDir]/templates
directory with the render function using related context data,
and writes generated contents to the files in output directory. If render function returns undefined
for a template/database object pair no file is not written for that pair.
Template file names may contain variables and basic filter functions to change names of generated files.
Additionally copies all files in [rootDir]/files
to the output directory.
Returns: Promise<void>
Defined in: pg-generator.ts:47
pg-generator / GeneratorOptions
Options for generation and reverse engineering process. Options extends pg-structure options
• Optional
clear: undefined | boolean
Whether to clear the destination directory before creating files.
Defined in: types/index.ts:7
• Optional
context: undefined | Record<string, any>
Extra context data. This data is merged with and overridden by data from context file.
Defined in: types/index.ts:13
• Optional
contextFile: undefined | string
Path to a JSON or JS file providing extra context for templates.
Defined in: types/index.ts:11
• Optional
log: undefined | boolean
Whether to log output to console.
Defined in: types/index.ts:15
• Optional
outDir: undefined | string
Path of the output directory.
Defined in: types/index.ts:9
pg-generator / filterFunctions
▸ camelCase(input
: string): string
Converts the given input to the camel case.
camelCase("user-name"); // userName
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string as camel case.
Defined in: utils/filter-functions.ts:48
▸ classCase(input
: string): string
Converts the given input to the class name.
classCase("user-name"); // UserName
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string as class case.
Defined in: utils/filter-functions.ts:74
▸ clearDefault(input?
: string): string | undefined
Clears the default value of a database object.
- Converts two quotes
''
to single quote'
- Removes quotes at the start and end of string.
- Escapes result according to JSON standards.
clearDefaultValue("'No ''value'' given'"); // "No value 'given'"
Name | Type | Description |
---|---|---|
input? |
string | is the default for a database object. |
Returns: string | undefined
default value to be used in a template.
Defined in: utils/filter-functions.ts:26
▸ dashCase(input
: string): string
Converts the given input to the dash case.
dashCase("User Name"); // user-name
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string as dash case.
Defined in: utils/filter-functions.ts:100
▸ dboClassName(object
: DbObject, schema?
: boolean): string
Returns given the given database object name as a class name.
Name | Type | Default value | Description |
---|---|---|---|
object |
DbObject | - | is the object to get the name as a class name. |
schema |
boolean | false | is whether to include schema name. |
Returns: string
Defined in: utils/filter-functions.ts:319
▸ dboColumnTypeModifier(column
: Column): string
Returns column length, precision and scale ready to be used in templates.
columnTypeModifier(price); // (10,4)
columnTypeModifier(name); // (20)
Name | Type | Description |
---|---|---|
column |
Column | is the column to get details. |
Returns: string
modifier string.
Defined in: utils/filter-functions.ts:333
▸ lcFirst(input
: string): string
Converts the given input's first letter to the lower case.
plural("User_name"); // User_name
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string with lower first case.
Defined in: utils/filter-functions.ts:139
▸ makeJsDoc(input?
: string): string
Converts given string to JSOC lines by adding "*" at the start of each line.
makeJsDoc(`
Text line 1
Text line 2
`);
// * Text line 1
// * Text line 1
returs
the result string.
Name | Type | Default value | Description |
---|---|---|---|
input |
string | "" | is the input string to convert. |
Returns: string
Defined in: utils/filter-functions.ts:237
▸ padRight(input
: string, totalLength
: number, paddingString?
: string): string
Pads given string's end with given padding string to complete its length to count.
Name | Type | Default value | Description |
---|---|---|---|
input |
string | - | is the input string to convert. |
totalLength |
number | - | is the total length of the result string. |
paddingString |
string | " " | is the string to pad with. |
Returns: string
the string padded with padding string.
Defined in: utils/filter-functions.ts:216
▸ pascalCase(input
: string): string
Converts the given input to the pascal case.
pascalCase("user-name"); // UserName
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string as pascal case.
Defined in: utils/filter-functions.ts:61
▸ plural(input
: string): string
Converts the given input to the plural form.
plural("user_name"); // user_names
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string in plural form.
Defined in: utils/filter-functions.ts:126
▸ quote(input
: string): string
Wraps the given string with quotes.
plural("user_name"); // "user_name"
Name | Type | Description |
---|---|---|
input |
string | is the input string to wrap with quotes. |
Returns: string
string with quotes.
Defined in: utils/filter-functions.ts:152
▸ singleLine(input
: string): string
If given data is a multi line string replcaes new lines with escape characters. May be used to prevent JS multi line errors.
Name | Type | Description |
---|---|---|
input |
string | is the input to convert. |
Returns: string
the string with escape characters.
Defined in: utils/filter-functions.ts:293
▸ singleQuote(input
: string): string
Wraps the given string with single quotes.
plural("Some 'example' text"); // 'some \'example\' text'
Name | Type | Description |
---|---|---|
input |
string | is the input string to wrap with quotes. |
Returns: string
string with quotes.
Defined in: utils/filter-functions.ts:165
▸ singular(input
: string): string
Converts the given input to the singular form.
singular("user_names"); // user_name
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string in singular form.
Defined in: utils/filter-functions.ts:113
▸ snakeCase(input
: string): string
Converts the given input to the snake case.
snakeCase("userName"); // user_name
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
Returns: string
string as snake case.
Defined in: utils/filter-functions.ts:87
▸ stringify(input
: any, options?
: { nullToUndef?
: boolean ; raw?
: boolean }): string
If given data is object or array, converts it to string.
- If it has
toString
method uses it. If it returns [object Object] tries other steps. - Uses
util.inspect()
;
Name | Type | Description |
---|---|---|
input |
any | is the input to convert. |
options |
object | - |
options.nullToUndef? |
boolean | - |
options.raw? |
boolean | - |
Returns: string
converted value.
Defined in: utils/filter-functions.ts:270
▸ strip(input
: string, ...removeList
: (string | { name
: string })[]): string
Vairadic function which strips all of the given strings or database object's names from the source string.
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
...removeList |
(string | { name : string })[] |
is the list of strings or objects to remove from input. |
Returns: string
converted string.
Defined in: utils/filter-functions.ts:202
▸ stripPrefix(input
: string, ...removeList
: (string | { name
: string })[]): string
Vairadic function which strips all of the given strings or database object's names from the start of the source string.
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
...removeList |
(string | { name : string })[] |
is the list of strings or objects to remove from input. |
Returns: string
converted string.
Defined in: utils/filter-functions.ts:176
▸ stripSuffix(input
: string, ...removeList
: (string | { name
: string })[]): string
Vairadic function which strips all of the given strings or database object's names from the end of the source string.
Name | Type | Description |
---|---|---|
input |
string | is the input string to convert. |
...removeList |
(string | { name : string })[] |
is the list of strings or objects to remove from input. |
Returns: string
converted string.
Defined in: utils/filter-functions.ts:189
▸ uniqueArray<T>(input
: T[]): T[]
Returns given array with unique elements by eliminating duplicate values.
Name | Type |
---|---|
T |
unknown |
Name | Type | Description |
---|---|---|
input |
T[] | is the input array to eliminate duplicates from. |
Returns: T[]
the array with unique values.
Defined in: utils/filter-functions.ts:303