4.8.3 • Published 3 years ago

pg-generator v4.8.3

Weekly downloads
1,454
License
MIT
Repository
github
Last release
3 years ago

pg-generator

Template based scaffolding tool for PostgreSQL.

Installation

Synopsis

Details

API

Table of contents

Namespaces

Classes

Interfaces

Type aliases

Context

Ƭ Context: object

Context provided to render function.

Type declaration:

NameType
oDb | DbObject
xRecord<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:

NameTypeDescription
generatorstringis the name or path of the generator. If it is a local path, use require.resolve or provide an absolute path.
options?Optionsare 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:

NameTypeDescription
generatorstringis the name or path of the generator. If it is a local path, use require.resolve or provide an absolute path.
subGenerator?stringis the name of the generator.
options?Optionsare 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

NameTypeDefault
OGeneratorOptionsGeneratorOptions

Constructors

constructor

+ new PgGenerator<O>(options: O, internalOptions: InternalOptions): PgGenerator<O>

Creates an instance of PgGenerator.

Type parameters:

NameTypeDefault
OGeneratorOptionsGeneratorOptions

Parameters:

NameTypeDescription
optionsOare parameters for several options.
internalOptionsInternalOptionsare 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
input?stringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDefault valueDescription
objectDbObject-is the object to get the name as a class name.
schemabooleanfalseis 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:

NameTypeDescription
columnColumnis 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:

NameTypeDescription
inputstringis 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:

NameTypeDefault valueDescription
inputstring""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:

NameTypeDefault valueDescription
inputstring-is the input string to convert.
totalLengthnumber-is the total length of the result string.
paddingStringstring" "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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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.

  1. If it has toString method uses it. If it returns object Object tries other steps.
  2. Uses util.inspect();

Parameters:

NameTypeDescription
inputanyis the input to convert.
optionsobject-
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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameTypeDescription
inputstringis 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:

NameType
Tunknown

Parameters:

NameTypeDescription
inputT[]is the input array to eliminate duplicates from.

Returns: T[]

the array with unique values.

Defined in: utils/filter-functions.ts:303

5.0.0-alpha.7

3 years ago

5.0.0-alpha.9

3 years ago

5.0.0-alpha.8

3 years ago

5.0.0-alpha.6

3 years ago

5.0.0-alpha.5

3 years ago

5.0.0-alpha.4

3 years ago

5.0.0-alpha.3

3 years ago

5.0.0-alpha.2

3 years ago

5.0.0-alpha.1

3 years ago

4.8.3

4 years ago

4.8.2

5 years ago

4.8.0

6 years ago

4.7.7

6 years ago

4.7.5

6 years ago

4.7.4

6 years ago

4.7.3

6 years ago

4.7.2

6 years ago

4.7.1

6 years ago

4.7.0

6 years ago

4.6.2

6 years ago

4.6.1

6 years ago

4.6.0

6 years ago

4.5.2

6 years ago

4.5.1

6 years ago

4.5.0

6 years ago

4.4.9

6 years ago

4.4.8

6 years ago

4.4.7

6 years ago

4.4.6

6 years ago

4.4.5

6 years ago

4.4.4

6 years ago

4.4.3

6 years ago

4.4.2

6 years ago

4.4.1

6 years ago

4.4.0

6 years ago

4.3.2

6 years ago

4.3.1

6 years ago

4.3.0

6 years ago

4.2.0

6 years ago

4.1.8

6 years ago

4.1.7

6 years ago

4.1.6

6 years ago

4.1.5

6 years ago

4.1.4

6 years ago

4.1.3

6 years ago

4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.2

7 years ago

3.6.0

7 years ago

3.5.0

7 years ago

3.4.15

7 years ago

3.4.14

7 years ago

3.4.13

7 years ago

3.4.12

7 years ago

3.4.11

7 years ago

3.4.10

7 years ago

3.4.9

7 years ago

3.4.8

7 years ago

3.4.7

7 years ago

3.4.6

7 years ago

3.4.5

7 years ago

3.4.4

7 years ago

3.4.2

8 years ago

3.4.1

8 years ago

3.4.0

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.14

8 years ago

3.2.13

8 years ago

3.2.12

8 years ago

3.2.11

8 years ago

3.2.10

8 years ago

3.2.9

8 years ago

3.2.7

8 years ago

3.2.6

8 years ago

3.2.5

8 years ago

3.2.4

8 years ago

3.2.3

8 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.3

8 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.20

8 years ago

2.0.19

8 years ago

2.0.18

8 years ago

2.0.17

8 years ago

2.0.16

8 years ago

2.0.15

8 years ago

2.0.14

8 years ago

2.0.13

8 years ago

2.0.12

8 years ago

2.0.11

8 years ago

2.0.10

8 years ago

2.0.9

8 years ago

2.0.8

8 years ago

2.0.7

8 years ago

2.0.6

8 years ago

2.0.5

8 years ago

2.0.4

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago