pg-generator v3.3.0
pg-generator
Template based scaffolding tool for PostgreSQL.
- Installation
- Synopsis
- Details
- API
- Classes
- Class: PgGenerator<O>
- Interfaces
- Interface: GeneratorOptions
- Modules
- Namespace: filterFunctions
Installation
Synopsis
Details
API
Table of contents
Namespaces
Classes
Interfaces
Type aliases
Context
Ƭ Context: object
Context provided to render function.
Type declaration:
Name | Type |
---|---|
o | Db | DbObject |
x | Record<string, any> |
Defined in: types/index.ts:53
Options
Ƭ Options: GeneratorOptions & ClientOptions
Defined in: types/index.ts:50
Functions
generate
▸ generate(generator
: string, options?
: Options): Promise<void>
Executes the default sub-generator app
from a generator.
Example
generate("generator-from-npm", options);
generate(require.resolve("./local-generator"), options);
Parameters:
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.
Example
generate("generator-from-npm", "sub-generator");
generate(require.resolve("./local-generator"), "sub-generator", options);
Parameters:
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
Classes
pg-generator / PgGenerator
Class: PgGenerator<O>
Base abstract class for for pg-generator classes.
Type parameters
Name | Type | Default |
---|---|---|
O | GeneratorOptions | GeneratorOptions |
Constructors
constructor
+ new PgGenerator<O>(options
: O, internalOptions
: InternalOptions): PgGenerator<O>
Creates an instance of PgGenerator.
Type parameters:
Name | Type | Default |
---|---|---|
O | GeneratorOptions | GeneratorOptions |
Parameters:
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
Methods
generate
▸ 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
Interfaces
pg-generator / GeneratorOptions
Interface: GeneratorOptions
Options for generation and reverse engineering process. Options extends pg-structure options
Properties
clear
• Optional
clear: undefined | boolean
Whether to clear the destination directory before creating files.
Defined in: types/index.ts:7
context
• 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
contextFile
• Optional
contextFile: undefined | string
Path to a JSON or JS file providing extra context for templates.
Defined in: types/index.ts:11
log
• Optional
log: undefined | boolean
Whether to log output to console.
Defined in: types/index.ts:15
outDir
• Optional
outDir: undefined | string
Path of the output directory.
Defined in: types/index.ts:9
Modules
pg-generator / filterFunctions
Namespace: filterFunctions
Functions
camelCase
▸ camelCase(input
: string): string
Converts the given input to the camel case.
Example
camelCase("user-name"); // userName
Parameters:
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
▸ classCase(input
: string): string
Converts the given input to the class name.
Example
classCase("user-name"); // UserName
Parameters:
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
▸ 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.
Example
clearDefaultValue("'No ''value'' given'"); // "No value 'given'"
Parameters:
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
▸ dashCase(input
: string): string
Converts the given input to the dash case.
Example
dashCase("User Name"); // user-name
Parameters:
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
▸ dboClassName(object
: DbObject, schema?
: boolean): string
Returns given the given database object name as a class name.
Parameters:
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
▸ dboColumnTypeModifier(column
: Column): string
Returns column length, precision and scale ready to be used in templates.
Example
columnTypeModifier(price); // (10,4)
columnTypeModifier(name); // (20)
Parameters:
Name | Type | Description |
---|---|---|
column | Column | is the column to get details. |
Returns: string
modifier string.
Defined in: utils/filter-functions.ts:333
lcFirst
▸ lcFirst(input
: string): string
Converts the given input's first letter to the lower case.
Example
plural("User_name"); // User_name
Parameters:
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
▸ makeJsDoc(input?
: string): string
Converts given string to JSOC lines by adding "*" at the start of each line.
Example
makeJsDoc(`
Text line 1
Text line 2
`);
// * Text line 1
// * Text line 1
returs
the result string.
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
input | string | "" | is the input string to convert. |
Returns: string
Defined in: utils/filter-functions.ts:237
padRight
▸ padRight(input
: string, totalLength
: number, paddingString?
: string): string
Pads given string's end with given padding string to complete its length to count.
Parameters:
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
▸ pascalCase(input
: string): string
Converts the given input to the pascal case.
Example
pascalCase("user-name"); // UserName
Parameters:
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
▸ plural(input
: string): string
Converts the given input to the plural form.
Example
plural("user_name"); // user_names
Parameters:
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
▸ quote(input
: string): string
Wraps the given string with quotes.
Example
plural("user_name"); // "user_name"
Parameters:
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
▸ 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.
Parameters:
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
▸ singleQuote(input
: string): string
Wraps the given string with single quotes.
Example
plural("Some 'example' text"); // 'some \'example\' text'
Parameters:
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
▸ singular(input
: string): string
Converts the given input to the singular form.
Example
singular("user_names"); // user_name
Parameters:
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
▸ snakeCase(input
: string): string
Converts the given input to the snake case.
Example
snakeCase("userName"); // user_name
Parameters:
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
▸ 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()
;
Parameters:
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
▸ 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.
Parameters:
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
▸ 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.
Parameters:
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
▸ 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.
Parameters:
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
▸ uniqueArray<T>(input
: T[]): T[]
Returns given array with unique elements by eliminating duplicate values.
Type parameters:
Name | Type |
---|---|
T | unknown |
Parameters:
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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago