feliking

Inicial

Showing 85 changed files with 4333 additions and 0 deletions
1 +
2 +# Created by https://www.gitignore.io/api/node,webstorm,visualstudiocode,macos,windows,linux
3 +
4 +### Linux ###
5 +*~
6 +
7 +# temporary files which can be created if a process still has a handle open of a deleted file
8 +.fuse_hidden*
9 +
10 +# KDE directory preferences
11 +.directory
12 +
13 +# Linux trash folder which might appear on any partition or disk
14 +.Trash-*
15 +
16 +# .nfs files are created when an open file is removed but is still being accessed
17 +.nfs*
18 +
19 +### macOS ###
20 +*.DS_Store
21 +.AppleDouble
22 +.LSOverride
23 +
24 +# Icon must end with two \r
25 +Icon
26 +
27 +
28 +# Thumbnails
29 +._*
30 +
31 +# Files that might appear in the root of a volume
32 +.DocumentRevisions-V100
33 +.fseventsd
34 +.Spotlight-V100
35 +.TemporaryItems
36 +.Trashes
37 +.VolumeIcon.icns
38 +.com.apple.timemachine.donotpresent
39 +
40 +# Directories potentially created on remote AFP share
41 +.AppleDB
42 +.AppleDesktop
43 +Network Trash Folder
44 +Temporary Items
45 +.apdisk
46 +
47 +### Node ###
48 +# Logs
49 +logs
50 +*.log
51 +npm-debug.log*
52 +yarn-debug.log*
53 +yarn-error.log*
54 +
55 +# Runtime data
56 +pids
57 +*.pid
58 +*.seed
59 +*.pid.lock
60 +
61 +# Directory for instrumented libs generated by jscoverage/JSCover
62 +lib-cov
63 +
64 +# Coverage directory used by tools like istanbul
65 +coverage
66 +
67 +# nyc test coverage
68 +.nyc_output
69 +
70 +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
71 +.grunt
72 +
73 +# Bower dependency directory (https://bower.io/)
74 +bower_components
75 +
76 +# node-waf configuration
77 +.lock-wscript
78 +
79 +# Compiled binary addons (http://nodejs.org/api/addons.html)
80 +build/Release
81 +
82 +# Dependency directories
83 +node_modules/
84 +jspm_packages/
85 +
86 +# Typescript v1 declaration files
87 +typings/
88 +
89 +# Optional npm cache directory
90 +.npm
91 +
92 +# Optional eslint cache
93 +.eslintcache
94 +
95 +# Optional REPL history
96 +.node_repl_history
97 +
98 +# Output of 'npm pack'
99 +*.tgz
100 +
101 +# Yarn Integrity file
102 +.yarn-integrity
103 +
104 +# dotenv environment variables file
105 +.env
106 +
107 +
108 +### VisualStudioCode ###
109 +.vscode/*
110 +!.vscode/settings.json
111 +!.vscode/tasks.json
112 +!.vscode/launch.json
113 +!.vscode/extensions.json
114 +
115 +### WebStorm ###
116 +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
117 +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
118 +
119 +# User-specific stuff:
120 +.idea/**/workspace.xml
121 +.idea/**/tasks.xml
122 +.idea/dictionaries
123 +
124 +# Sensitive or high-churn files:
125 +.idea/**/dataSources/
126 +.idea/**/dataSources.ids
127 +.idea/**/dataSources.xml
128 +.idea/**/dataSources.local.xml
129 +.idea/**/sqlDataSources.xml
130 +.idea/**/dynamic.xml
131 +.idea/**/uiDesigner.xml
132 +
133 +# Gradle:
134 +.idea/**/gradle.xml
135 +.idea/**/libraries
136 +
137 +# Mongo Explorer plugin:
138 +.idea/**/mongoSettings.xml
139 +
140 +## File-based project format:
141 +*.iws
142 +
143 +## Plugin-specific files:
144 +
145 +# IntelliJ
146 +/out/
147 +
148 +# mpeltonen/sbt-idea plugin
149 +.idea_modules/
150 +
151 +# JIRA plugin
152 +atlassian-ide-plugin.xml
153 +
154 +# Cursive Clojure plugin
155 +.idea/replstate.xml
156 +
157 +# Crashlytics plugin (for Android Studio and IntelliJ)
158 +com_crashlytics_export_strings.xml
159 +crashlytics.properties
160 +crashlytics-build.properties
161 +fabric.properties
162 +
163 +### WebStorm Patch ###
164 +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
165 +
166 +# *.iml
167 +# modules.xml
168 +# .idea/misc.xml
169 +# *.ipr
170 +
171 +# Sonarlint plugin
172 +.idea/sonarlint
173 +
174 +### Windows ###
175 +# Windows thumbnail cache files
176 +Thumbs.db
177 +ehthumbs.db
178 +ehthumbs_vista.db
179 +
180 +# Folder config file
181 +Desktop.ini
182 +
183 +# Recycle Bin used on file shares
184 +$RECYCLE.BIN/
185 +
186 +# Windows Installer files
187 +*.cab
188 +*.msi
189 +*.msm
190 +*.msp
191 +
192 +# Windows shortcuts
193 +*.lnk
194 +
195 +# End of https://www.gitignore.io/api/node,webstorm,visualstudiocode,macos,windows,linux
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="ProjectModuleManager">
4 + <modules>
5 + <module fileurl="file://$PROJECT_DIR$/.idea/sequelize-pg-generator.iml" filepath="$PROJECT_DIR$/.idea/sequelize-pg-generator.iml" />
6 + </modules>
7 + </component>
8 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<module type="WEB_MODULE" version="4">
3 + <component name="NewModuleRootManager">
4 + <content url="file://$MODULE_DIR$">
5 + <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6 + <excludeFolder url="file://$MODULE_DIR$/temp" />
7 + <excludeFolder url="file://$MODULE_DIR$/tmp" />
8 + </content>
9 + <orderEntry type="inheritedJdk" />
10 + <orderEntry type="sourceFolder" forTests="false" />
11 + </component>
12 +</module>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="VcsDirectoryMappings">
4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +
2 +---------------------------------------
3 +
4 +<a name="History"></a>
5 +History & Release Notes
6 +=======================
7 +
8 +Note
9 +----
10 +Version history for minimal documentation updates are not listed here to prevent cluttering.
11 +
12 +###### 0.9.0
13 +* Added: sequelize-types are added. (pg-structure deprecated it.)
14 +
15 +###### 0.8.0 / 2015-10-14
16 +* Added: `alias.json` file is generated in target directory to let developer easily override relationship names.
17 +
18 +###### 0.7.0 / 2015-10-14
19 +* Changed: Location of utils.js is changed to inside of model directory.
20 +
21 +###### 0.6.0 / 2015-09-10
22 +* -t --templateName parameter added to spgen. This name is used to choose one of the builtin template directories.
23 +* sequalize4 template added for protect backward compatibility.
24 +* sequalize4 template supports object references property. (references and referencesKey will be depreciated in Sequelize 4)
25 +
26 +###### 0.5.4 / 2015-06-16
27 +* pg-structure updated to latest version.
28 +
29 +###### 0.5.3 / 2015-06-16
30 +* Added: JSONB support and Boolean default value. Contributed by viniciuspinto (https://github.com/viniciuspinto)
31 +
32 +###### 0.4.2 / 2015-04-27
33 +* Added documentation and examples.
34 +
35 +###### 0.3.1 / 2015-01-10
36 +* Tested for Sequelize 2.0 RC7
37 +
38 +###### 0.3.0 / 2014-12-30
39 +* Removed: pg-native dependency removed. Some users experienced problems during install.
40 +* Added: generate.addRelationNameToManyToMany configuration to prefix relation aliases prevent further name clashes which cannot be prevented by generate.addTableNameToManyToMany. Default: true.
41 +* Added: generate.stripFirstTableNameFromManyToMany configuration added. Default: true
42 +* Changed: generate.addTableNameToManyToMany configuration default is false now.
43 +* Changed: Default naming rule for many to many relations.
44 +* Added: Logging uses Winston module now.
45 +* Added: Doc update for Windows OS users.
46 +* Fixed: Database tables without any column throws error when warning configuration is true.
47 +
48 +###### 0.2.0 / 2014-12-27
49 +* Added: Automatic alias and naming validations to prevent name clash.
50 +* Added: generate.addTableNameToManyToMany configuration to prefix relation aliases prevent name clash. Default: true.
51 +* Added: --throwError option added to CLI. This option decides wheter to throw error or simply log.
52 +* Added: Prevent hasMany through and belongsToMany true at the same time.
53 +* Fixed: generate.prefixForBelongsTo aliases are not properly camel cased.
54 +* Fixed: --resetConfig option does not work from CLI
55 +* Doc update
56 +
57 +###### 0.1.17 / 2014-12-26
58 +* Fixed: CLI command does not work.
59 +* Added: Required parameters warning.
60 +
61 +###### 0.1.15 / 2014-12-26
62 +* Added: Turkish documentation added.
63 +* Fixed: Typos and mistakes in documents.
64 +
65 +###### 0.1.12 / 2014-12-23
66 +* Added: Tests added.
67 +* Added: --nolog option added to spgen command.
68 +* Added: --resetConfig option. Also details and caveat added to the document.
69 +* Fix: lib/index.js exported function expects different parameters than written in documentation.
70 +* Fix: Command line arguments fixed.
71 +* Fix: Data type variable name configuration is ignored.
72 +* Document update.
73 +
74 +###### 0.1.0 / 2014-12-23
75 +* Initial version.
76 +
1 +The MIT License (MIT)
2 +
3 +Copyright (c) 2014 Özüm Eldoğan
4 +
5 +Permission is hereby granted, free of charge, to any person obtaining a copy
6 +of this software and associated documentation files (the "Software"), to deal
7 +in the Software without restriction, including without limitation the rights
8 +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom the Software is
10 +furnished to do so, subject to the following conditions:
11 +
12 +The above copyright notice and this permission notice shall be included in all
13 +copies or substantial portions of the Software.
14 +
15 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 +SOFTWARE.
22 +
1 +REPORTER = list
2 +
3 +test:
4 + clear
5 + echo Starting test *********************************************************
6 + ./node_modules/mocha/bin/mocha
7 + echo Ending test
8 +
9 +doc:
10 + clear
11 + echo Starting JSDOC *********************************************************
12 + jsdoc -c jsdoc-conf.json README-JSDOC.md
13 + echo Creating README.md *****************************************************
14 + rm -f README.md
15 + jsdoc2md --src lib/index.js template/utils.js template/index.js >>JSDOC.md
16 + cat README-JSDOC.md JSDOC.md History.md LICENSE > README.md
17 + cat README-JSDOC-TR.md JSDOC.md History.md LICENSE > README-TR.md
18 + rm -r -f JSDOC.md
19 +
20 +.PHONY: test doc
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +/*jslint node: true, nomen: true*/
2 +"use strict";
3 +
4 +var path = require('path');
5 +
6 +module.exports = {
7 + "sequelize-pg-generator": {
8 + "database": {
9 + "host": "127.0.0.1",
10 + "port": 5432,
11 + "user": "user",
12 + "password": "password",
13 + "database": "",
14 + "schema": ["public"]
15 + },
16 + "template": {
17 + "engine": "swig",
18 + "extension": "html",
19 + "folder": path.join(__dirname, '..', 'template', 'default')
20 + },
21 + "output": {
22 + "log": true,
23 + "folder": "../../../src/infraestructure/model",
24 + "beautify": true,
25 + "indent": 2,
26 + "preserveNewLines": false,
27 + "warning": true
28 + },
29 + "generate": {
30 + "stripFirstTableFromHasMany": true,
31 + "addTableNameToManyToMany": false,
32 + "addRelationNameToManyToMany": true,
33 + "stripFirstTableNameFromManyToMany": true,
34 + "hasManyThrough": false,
35 + "belongsToMany": true,
36 + "prefixForBelongsTo": "related",
37 + "useSchemaName": false,
38 + "modelCamelCase": true,
39 + "relationAccessorCamelCase": true,
40 + "columnAccessorCamelCase": false,
41 + "columnDefault": false,
42 + "columnDescription": true,
43 + "columnAutoIncrement": true,
44 + "tableDescription": true,
45 + "dataTypeVariable": "DataTypes",
46 + "skipTable": []
47 + },
48 + "tableOptions": {
49 + "timestamps": false
50 + }
51 + }
52 +};
This diff is collapsed. Click to expand it.
1 +<!DOCTYPE html>
2 +
3 +<html lang="en">
4 +<head>
5 + <meta charset="utf-8">
6 + <title>sequelize-pg-generator Classes</title>
7 +
8 + <!--[if lt IE 9]>
9 + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
10 + <![endif]-->
11 + <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
12 +
13 + <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
14 +
15 +</head>
16 +
17 +<body>
18 +<div class="container-fluid">
19 + <div class="navbar navbar-fixed-top navbar-inverse">
20 + <div class="navbar-inner">
21 + <a class="brand" href="index.html">sequelize-pg-generator</a>
22 + <ul class="nav">
23 +
24 + <li class="dropdown">
25 + <a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
26 + class="caret"></b></a>
27 +
28 + <ul class="dropdown-menu ">
29 +
30 + <li>
31 + <a href="module-lib_index.html">lib/index</a>
32 + </li>
33 +
34 + <li>
35 + <a href="module-path_to_model.html">path/to/model</a>
36 + </li>
37 +
38 +
39 + </ul>
40 + </li>
41 +
42 + <li class="dropdown">
43 + <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
44 + class="caret"></b></a>
45 +
46 + <ul class="dropdown-menu ">
47 +
48 + <li>
49 + <a href="GeneratorUtil.html">GeneratorUtil</a>
50 + </li>
51 +
52 +
53 + </ul>
54 + </li>
55 +
56 + </ul>
57 + </div>
58 + </div>
59 +
60 + <div class="row-fluid">
61 +
62 +
63 + <div class="span8">
64 +
65 + <div id="main">
66 +
67 +
68 +
69 + <h1 class="page-title">Classes</h1>
70 +<section>
71 +
72 +<header>
73 + <h2>
74 +
75 + </h2>
76 +
77 +</header>
78 +
79 +<article>
80 + <div class="container-overview">
81 +
82 +
83 +
84 +
85 +
86 +
87 +<dl class="details">
88 +
89 +
90 +
91 +
92 +
93 +
94 +
95 +
96 +
97 +
98 +
99 +
100 +
101 +
102 +
103 +
104 +
105 +
106 +
107 +
108 +
109 +
110 +
111 +
112 +
113 +
114 +
115 +</dl>
116 +
117 +
118 +
119 +
120 + </div>
121 +
122 +
123 +
124 +
125 +
126 +
127 +
128 +
129 + <h3 class="subsection-title">Classes</h3>
130 +
131 + <dl>
132 + <dt><a href="GeneratorUtil.html">GeneratorUtil</a></dt>
133 + <dd></dd>
134 + </dl>
135 +
136 +
137 +
138 +
139 +
140 +
141 +
142 +
143 +
144 +
145 +
146 +</article>
147 +
148 +</section>
149 +
150 +
151 +
152 +
153 + </div>
154 +
155 + <div class="clearfix"></div>
156 + <footer>
157 +
158 +
159 + <span class="copyright">
160 + sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.
161 + </span>
162 + <br />
163 +
164 + <span class="jsdoc-message">
165 + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a>
166 + on Fri Nov 27th 2015 using the <a
167 + href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
168 + </span>
169 + </footer>
170 + </div>
171 +
172 +
173 + <div class="span3">
174 + <div id="toc"></div>
175 + </div>
176 +
177 + <br clear="both">
178 + </div>
179 +
180 + </div>
181 + <!--<script src="scripts/sunlight.js"></script>-->
182 + <script src="scripts/docstrap.lib.js"></script>
183 + <script src="scripts/bootstrap-dropdown.js"></script>
184 + <script src="scripts/toc.js"></script>
185 +
186 + <script>
187 + $( function () {
188 + $( "[id*='$']" ).each( function () {
189 + var $this = $( this );
190 +
191 + $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
192 + } );
193 +
194 + $( "#toc" ).toc( {
195 + anchorName : function ( i, heading, prefix ) {
196 + return $( heading ).attr( "id" ) || ( prefix + i );
197 + },
198 + selectors : "h1,h2,h3,h4",
199 + showAndHide : false,
200 + scrollTo : "100px"
201 + } );
202 +
203 + $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
204 + $( "#main span[id^='toc']" ).addClass( "toc-shim" );
205 + $( '.dropdown-toggle' ).dropdown();
206 +// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
207 +
208 + $( ".tutorial-section pre, .readme-section pre" ).each( function () {
209 + var $this = $( this );
210 +
211 + var example = $this.find( "code" );
212 + exampleText = example.html();
213 + var lang = /{@lang (.*?)}/.exec( exampleText );
214 + if ( lang && lang[1] ) {
215 + exampleText = exampleText.replace( lang[0], "" );
216 + example.html( exampleText );
217 + lang = lang[1];
218 + } else {
219 + lang = "javascript";
220 + }
221 +
222 + if ( lang ) {
223 +
224 + $this
225 + .addClass( "sunlight-highlight-" + lang )
226 + .addClass( "linenums" )
227 + .html( example.html() );
228 +
229 + }
230 + } );
231 +
232 + Sunlight.highlightAll( {
233 + lineNumbers : true,
234 + showMenu : true,
235 + enableDoclinks : true
236 + } );
237 + } );
238 + </script>
239 +
240 +
241 +
242 + <!--Navigation and Symbol Display-->
243 +
244 +
245 +
246 + <!--Google Analytics-->
247 +
248 +
249 +</body>
250 +</html>
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +<!DOCTYPE html>
2 +
3 +<html lang="en">
4 +<head>
5 + <meta charset="utf-8">
6 + <title>sequelize-pg-generator Modules</title>
7 +
8 + <!--[if lt IE 9]>
9 + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
10 + <![endif]-->
11 + <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
12 +
13 + <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
14 +
15 +</head>
16 +
17 +<body>
18 +<div class="container-fluid">
19 + <div class="navbar navbar-fixed-top navbar-inverse">
20 + <div class="navbar-inner">
21 + <a class="brand" href="index.html">sequelize-pg-generator</a>
22 + <ul class="nav">
23 +
24 + <li class="dropdown">
25 + <a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
26 + class="caret"></b></a>
27 +
28 + <ul class="dropdown-menu ">
29 +
30 + <li>
31 + <a href="module-lib_index.html">lib/index</a>
32 + </li>
33 +
34 + <li>
35 + <a href="module-path_to_model.html">path/to/model</a>
36 + </li>
37 +
38 +
39 + </ul>
40 + </li>
41 +
42 + <li class="dropdown">
43 + <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
44 + class="caret"></b></a>
45 +
46 + <ul class="dropdown-menu ">
47 +
48 + <li>
49 + <a href="GeneratorUtil.html">GeneratorUtil</a>
50 + </li>
51 +
52 +
53 + </ul>
54 + </li>
55 +
56 + </ul>
57 + </div>
58 + </div>
59 +
60 + <div class="row-fluid">
61 +
62 +
63 + <div class="span8">
64 +
65 + <div id="main">
66 +
67 +
68 +
69 + <h1 class="page-title">Modules</h1>
70 +<section>
71 +
72 +<header>
73 + <h2>
74 +
75 + </h2>
76 +
77 +</header>
78 +
79 +<article>
80 + <div class="container-overview">
81 +
82 +
83 +
84 +
85 +
86 +
87 +<dl class="details">
88 +
89 +
90 +
91 +
92 +
93 +
94 +
95 +
96 +
97 +
98 +
99 +
100 +
101 +
102 +
103 +
104 +
105 +
106 +
107 +
108 +
109 +
110 +
111 +
112 +
113 +
114 +
115 +</dl>
116 +
117 +
118 +
119 +
120 + </div>
121 +
122 +
123 +
124 +
125 +
126 +
127 +
128 +
129 + <h3 class="subsection-title">Classes</h3>
130 +
131 + <dl>
132 + <dt><a href="GeneratorUtil.html">GeneratorUtil</a></dt>
133 + <dd></dd>
134 + </dl>
135 +
136 +
137 +
138 +
139 +
140 +
141 +
142 +
143 +
144 +
145 +
146 +</article>
147 +
148 +</section>
149 +
150 +
151 +
152 +
153 + </div>
154 +
155 + <div class="clearfix"></div>
156 + <footer>
157 +
158 +
159 + <span class="copyright">
160 + sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.
161 + </span>
162 + <br />
163 +
164 + <span class="jsdoc-message">
165 + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a>
166 + on Fri Nov 27th 2015 using the <a
167 + href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
168 + </span>
169 + </footer>
170 + </div>
171 +
172 +
173 + <div class="span3">
174 + <div id="toc"></div>
175 + </div>
176 +
177 + <br clear="both">
178 + </div>
179 +
180 + </div>
181 + <!--<script src="scripts/sunlight.js"></script>-->
182 + <script src="scripts/docstrap.lib.js"></script>
183 + <script src="scripts/bootstrap-dropdown.js"></script>
184 + <script src="scripts/toc.js"></script>
185 +
186 + <script>
187 + $( function () {
188 + $( "[id*='$']" ).each( function () {
189 + var $this = $( this );
190 +
191 + $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
192 + } );
193 +
194 + $( "#toc" ).toc( {
195 + anchorName : function ( i, heading, prefix ) {
196 + return $( heading ).attr( "id" ) || ( prefix + i );
197 + },
198 + selectors : "h1,h2,h3,h4",
199 + showAndHide : false,
200 + scrollTo : "100px"
201 + } );
202 +
203 + $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
204 + $( "#main span[id^='toc']" ).addClass( "toc-shim" );
205 + $( '.dropdown-toggle' ).dropdown();
206 +// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
207 +
208 + $( ".tutorial-section pre, .readme-section pre" ).each( function () {
209 + var $this = $( this );
210 +
211 + var example = $this.find( "code" );
212 + exampleText = example.html();
213 + var lang = /{@lang (.*?)}/.exec( exampleText );
214 + if ( lang && lang[1] ) {
215 + exampleText = exampleText.replace( lang[0], "" );
216 + example.html( exampleText );
217 + lang = lang[1];
218 + } else {
219 + lang = "javascript";
220 + }
221 +
222 + if ( lang ) {
223 +
224 + $this
225 + .addClass( "sunlight-highlight-" + lang )
226 + .addClass( "linenums" )
227 + .html( example.html() );
228 +
229 + }
230 + } );
231 +
232 + Sunlight.highlightAll( {
233 + lineNumbers : true,
234 + showMenu : true,
235 + enableDoclinks : true
236 + } );
237 + } );
238 + </script>
239 +
240 +
241 +
242 + <!--Navigation and Symbol Display-->
243 +
244 +
245 +
246 + <!--Google Analytics-->
247 +
248 +
249 +</body>
250 +</html>
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +/* ============================================================
2 + * bootstrap-dropdown.js v2.3.2
3 + * http://getbootstrap.com/2.3.2/javascript.html#dropdowns
4 + * ============================================================
5 + * Copyright 2013 Twitter, Inc.
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + * ============================================================ */
19 +
20 +
21 +!function ($) {
22 +
23 + "use strict"; // jshint ;_;
24 +
25 +
26 + /* DROPDOWN CLASS DEFINITION
27 + * ========================= */
28 +
29 + var toggle = '[data-toggle=dropdown]'
30 + , Dropdown = function (element) {
31 + var $el = $(element).on('click.dropdown.data-api', this.toggle)
32 + $('html').on('click.dropdown.data-api', function () {
33 + $el.parent().removeClass('open')
34 + })
35 + }
36 +
37 + Dropdown.prototype = {
38 +
39 + constructor: Dropdown
40 +
41 + , toggle: function (e) {
42 + var $this = $(this)
43 + , $parent
44 + , isActive
45 +
46 + if ($this.is('.disabled, :disabled')) return
47 +
48 + $parent = getParent($this)
49 +
50 + isActive = $parent.hasClass('open')
51 +
52 + clearMenus()
53 +
54 + if (!isActive) {
55 + if ('ontouchstart' in document.documentElement) {
56 + // if mobile we we use a backdrop because click events don't delegate
57 + $('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus)
58 + }
59 + $parent.toggleClass('open')
60 + }
61 +
62 + $this.focus()
63 +
64 + return false
65 + }
66 +
67 + , keydown: function (e) {
68 + var $this
69 + , $items
70 + , $active
71 + , $parent
72 + , isActive
73 + , index
74 +
75 + if (!/(38|40|27)/.test(e.keyCode)) return
76 +
77 + $this = $(this)
78 +
79 + e.preventDefault()
80 + e.stopPropagation()
81 +
82 + if ($this.is('.disabled, :disabled')) return
83 +
84 + $parent = getParent($this)
85 +
86 + isActive = $parent.hasClass('open')
87 +
88 + if (!isActive || (isActive && e.keyCode == 27)) {
89 + if (e.which == 27) $parent.find(toggle).focus()
90 + return $this.click()
91 + }
92 +
93 + $items = $('[role=menu] li:not(.divider):visible a', $parent)
94 +
95 + if (!$items.length) return
96 +
97 + index = $items.index($items.filter(':focus'))
98 +
99 + if (e.keyCode == 38 && index > 0) index-- // up
100 + if (e.keyCode == 40 && index < $items.length - 1) index++ // down
101 + if (!~index) index = 0
102 +
103 + $items
104 + .eq(index)
105 + .focus()
106 + }
107 +
108 + }
109 +
110 + function clearMenus() {
111 + $('.dropdown-backdrop').remove()
112 + $(toggle).each(function () {
113 + getParent($(this)).removeClass('open')
114 + })
115 + }
116 +
117 + function getParent($this) {
118 + var selector = $this.attr('data-target')
119 + , $parent
120 +
121 + if (!selector) {
122 + selector = $this.attr('href')
123 + selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
124 + }
125 +
126 + $parent = selector && $(selector)
127 +
128 + if (!$parent || !$parent.length) $parent = $this.parent()
129 +
130 + return $parent
131 + }
132 +
133 +
134 + /* DROPDOWN PLUGIN DEFINITION
135 + * ========================== */
136 +
137 + var old = $.fn.dropdown
138 +
139 + $.fn.dropdown = function (option) {
140 + return this.each(function () {
141 + var $this = $(this)
142 + , data = $this.data('dropdown')
143 + if (!data) $this.data('dropdown', (data = new Dropdown(this)))
144 + if (typeof option == 'string') data[option].call($this)
145 + })
146 + }
147 +
148 + $.fn.dropdown.Constructor = Dropdown
149 +
150 +
151 + /* DROPDOWN NO CONFLICT
152 + * ==================== */
153 +
154 + $.fn.dropdown.noConflict = function () {
155 + $.fn.dropdown = old
156 + return this
157 + }
158 +
159 +
160 + /* APPLY TO STANDARD DROPDOWN ELEMENTS
161 + * =================================== */
162 +
163 + $(document)
164 + .on('click.dropdown.data-api', clearMenus)
165 + .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
166 + .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
167 + .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
168 +
169 +}(window.jQuery);
1 +/* ========================================================
2 + * bootstrap-tab.js v2.3.0
3 + * http://twitter.github.com/bootstrap/javascript.html#tabs
4 + * ========================================================
5 + * Copyright 2012 Twitter, Inc.
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License");
8 + * you may not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS,
15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + * ======================================================== */
19 +
20 +
21 +!function ($) {
22 +
23 + "use strict"; // jshint ;_;
24 +
25 +
26 + /* TAB CLASS DEFINITION
27 + * ==================== */
28 +
29 + var Tab = function (element) {
30 + this.element = $(element)
31 + }
32 +
33 + Tab.prototype = {
34 +
35 + constructor: Tab
36 +
37 + , show: function () {
38 + var $this = this.element
39 + , $ul = $this.closest('ul:not(.dropdown-menu)')
40 + , selector = $this.attr('data-target')
41 + , previous
42 + , $target
43 + , e
44 +
45 + if (!selector) {
46 + selector = $this.attr('href')
47 + selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
48 + }
49 +
50 + if ( $this.parent('li').hasClass('active') ) return
51 +
52 + previous = $ul.find('.active:last a')[0]
53 +
54 + e = $.Event('show', {
55 + relatedTarget: previous
56 + })
57 +
58 + $this.trigger(e)
59 +
60 + if (e.isDefaultPrevented()) return
61 +
62 + $target = $(selector)
63 +
64 + this.activate($this.parent('li'), $ul)
65 + this.activate($target, $target.parent(), function () {
66 + $this.trigger({
67 + type: 'shown'
68 + , relatedTarget: previous
69 + })
70 + })
71 + }
72 +
73 + , activate: function ( element, container, callback) {
74 + var $active = container.find('> .active')
75 + , transition = callback
76 + && $.support.transition
77 + && $active.hasClass('fade')
78 +
79 + function next() {
80 + $active
81 + .removeClass('active')
82 + .find('> .dropdown-menu > .active')
83 + .removeClass('active')
84 +
85 + element.addClass('active')
86 +
87 + if (transition) {
88 + element[0].offsetWidth // reflow for transition
89 + element.addClass('in')
90 + } else {
91 + element.removeClass('fade')
92 + }
93 +
94 + if ( element.parent('.dropdown-menu') ) {
95 + element.closest('li.dropdown').addClass('active')
96 + }
97 +
98 + callback && callback()
99 + }
100 +
101 + transition ?
102 + $active.one($.support.transition.end, next) :
103 + next()
104 +
105 + $active.removeClass('in')
106 + }
107 + }
108 +
109 +
110 + /* TAB PLUGIN DEFINITION
111 + * ===================== */
112 +
113 + var old = $.fn.tab
114 +
115 + $.fn.tab = function ( option ) {
116 + return this.each(function () {
117 + var $this = $(this)
118 + , data = $this.data('tab')
119 + if (!data) $this.data('tab', (data = new Tab(this)))
120 + if (typeof option == 'string') data[option]()
121 + })
122 + }
123 +
124 + $.fn.tab.Constructor = Tab
125 +
126 +
127 + /* TAB NO CONFLICT
128 + * =============== */
129 +
130 + $.fn.tab.noConflict = function () {
131 + $.fn.tab = old
132 + return this
133 + }
134 +
135 +
136 + /* TAB DATA-API
137 + * ============ */
138 +
139 + $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
140 + e.preventDefault()
141 + $(this).tab('show')
142 + })
143 +
144 +}(window.jQuery);
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +PR.registerLangHandler(PR.createSimpleLexer([
2 + ["pln", /^[\t\n\f\r ]+/, null, " \t\r\n "]
3 +], [
4 + ["str", /^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/, null],
5 + ["str", /^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/, null],
6 + ["lang-css-str", /^url\(([^"')]*)\)/i],
7 + ["kwd", /^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i, null],
8 + ["lang-css-kw", /^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],
9 + ["com", /^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],
10 + ["com", /^(?:<\!--|--\>)/],
11 + ["lit", /^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],
12 + ["lit", /^#[\da-f]{3,6}/i],
13 + ["pln", /^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],
14 + ["pun", /^[^\s\w"']+/]
15 +]), ["css"]);
16 +PR.registerLangHandler(PR.createSimpleLexer([], [
17 + ["kwd", /^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]
18 +]), ["css-kw"]);
19 +PR.registerLangHandler(PR.createSimpleLexer([], [
20 + ["str", /^[^"')]+/]
21 +]), ["css-str"]);
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +(function($) {
2 +$.fn.toc = function(options) {
3 + var self = this;
4 + var opts = $.extend({}, jQuery.fn.toc.defaults, options);
5 +
6 + var container = $(opts.container);
7 + var headings = $(opts.selectors, container);
8 + var headingOffsets = [];
9 + var activeClassName = opts.prefix+'-active';
10 +
11 + var scrollTo = function(e) {
12 + if (opts.smoothScrolling) {
13 + e.preventDefault();
14 + var elScrollTo = $(e.target).attr('href');
15 + var $el = $(elScrollTo);
16 +
17 + $('body,html').animate({ scrollTop: $el.offset().top }, 400, 'swing', function() {
18 + location.hash = elScrollTo;
19 + });
20 + }
21 + $('li', self).removeClass(activeClassName);
22 + $(e.target).parent().addClass(activeClassName);
23 + };
24 +
25 + //highlight on scroll
26 + var timeout;
27 + var highlightOnScroll = function(e) {
28 + if (timeout) {
29 + clearTimeout(timeout);
30 + }
31 + timeout = setTimeout(function() {
32 + var top = $(window).scrollTop(),
33 + highlighted;
34 + for (var i = 0, c = headingOffsets.length; i < c; i++) {
35 + if (headingOffsets[i] >= top) {
36 + $('li', self).removeClass(activeClassName);
37 + highlighted = $('li:eq('+(i-1)+')', self).addClass(activeClassName);
38 + opts.onHighlight(highlighted);
39 + break;
40 + }
41 + }
42 + }, 50);
43 + };
44 + if (opts.highlightOnScroll) {
45 + $(window).bind('scroll', highlightOnScroll);
46 + highlightOnScroll();
47 + }
48 +
49 + return this.each(function() {
50 + //build TOC
51 + var el = $(this);
52 + var ul = $('<ul/>');
53 + headings.each(function(i, heading) {
54 + var $h = $(heading);
55 + headingOffsets.push($h.offset().top - opts.highlightOffset);
56 +
57 + //add anchor
58 + var anchor = $('<span/>').attr('id', opts.anchorName(i, heading, opts.prefix)).insertBefore($h);
59 +
60 + //build TOC item
61 + var a = $('<a/>')
62 + .text(opts.headerText(i, heading, $h))
63 + .attr('href', '#' + opts.anchorName(i, heading, opts.prefix))
64 + .bind('click', function(e) {
65 + scrollTo(e);
66 + el.trigger('selected', $(this).attr('href'));
67 + });
68 +
69 + var li = $('<li/>')
70 + .addClass(opts.itemClass(i, heading, $h, opts.prefix))
71 + .append(a);
72 +
73 + ul.append(li);
74 + });
75 + el.html(ul);
76 + });
77 +};
78 +
79 +
80 +jQuery.fn.toc.defaults = {
81 + container: 'body',
82 + selectors: 'h1,h2,h3',
83 + smoothScrolling: true,
84 + prefix: 'toc',
85 + onHighlight: function() {},
86 + highlightOnScroll: true,
87 + highlightOffset: 100,
88 + anchorName: function(i, heading, prefix) {
89 + return prefix+i;
90 + },
91 + headerText: function(i, heading, $heading) {
92 + return $heading.text();
93 + },
94 + itemClass: function(i, heading, $heading, prefix) {
95 + return prefix + '-' + $heading[0].tagName.toLowerCase();
96 + }
97 +
98 +};
99 +
100 +})(jQuery);
This diff is collapsed. Click to expand it.
1 +/* Tomorrow Theme */
2 +/* Original theme - https://github.com/chriskempson/tomorrow-theme */
3 +/* Pretty printing styles. Used with prettify.js. */
4 +/* SPAN elements with the classes below are added by prettyprint. */
5 +/* plain text */
6 +.pln {
7 + color: #4d4d4c; }
8 +
9 +@media screen {
10 + /* string content */
11 + .str {
12 + color: #718c00; }
13 +
14 + /* a keyword */
15 + .kwd {
16 + color: #8959a8; }
17 +
18 + /* a comment */
19 + .com {
20 + color: #8e908c; }
21 +
22 + /* a type name */
23 + .typ {
24 + color: #4271ae; }
25 +
26 + /* a literal value */
27 + .lit {
28 + color: #f5871f; }
29 +
30 + /* punctuation */
31 + .pun {
32 + color: #4d4d4c; }
33 +
34 + /* lisp open bracket */
35 + .opn {
36 + color: #4d4d4c; }
37 +
38 + /* lisp close bracket */
39 + .clo {
40 + color: #4d4d4c; }
41 +
42 + /* a markup tag name */
43 + .tag {
44 + color: #c82829; }
45 +
46 + /* a markup attribute name */
47 + .atn {
48 + color: #f5871f; }
49 +
50 + /* a markup attribute value */
51 + .atv {
52 + color: #3e999f; }
53 +
54 + /* a declaration */
55 + .dec {
56 + color: #f5871f; }
57 +
58 + /* a variable name */
59 + .var {
60 + color: #c82829; }
61 +
62 + /* a function name */
63 + .fun {
64 + color: #4271ae; } }
65 +/* Use higher contrast and text-weight for printable form. */
66 +@media print, projection {
67 + .str {
68 + color: #060; }
69 +
70 + .kwd {
71 + color: #006;
72 + font-weight: bold; }
73 +
74 + .com {
75 + color: #600;
76 + font-style: italic; }
77 +
78 + .typ {
79 + color: #404;
80 + font-weight: bold; }
81 +
82 + .lit {
83 + color: #044; }
84 +
85 + .pun, .opn, .clo {
86 + color: #440; }
87 +
88 + .tag {
89 + color: #006;
90 + font-weight: bold; }
91 +
92 + .atn {
93 + color: #404; }
94 +
95 + .atv {
96 + color: #060; } }
97 +/* Style */
98 +/*
99 +pre.prettyprint {
100 + background: white;
101 + font-family: Menlo, Monaco, Consolas, monospace;
102 + font-size: 12px;
103 + line-height: 1.5;
104 + border: 1px solid #ccc;
105 + padding: 10px; }
106 +*/
107 +
108 +/* Specify class=linenums on a pre to get line numbering */
109 +ol.linenums {
110 + margin-top: 0;
111 + margin-bottom: 0; }
112 +
113 +/* IE indents via margin-left */
114 +li.L0,
115 +li.L1,
116 +li.L2,
117 +li.L3,
118 +li.L4,
119 +li.L5,
120 +li.L6,
121 +li.L7,
122 +li.L8,
123 +li.L9 {
124 + /* */ }
125 +
126 +/* Alternate shading for lines */
127 +li.L1,
128 +li.L3,
129 +li.L5,
130 +li.L7,
131 +li.L9 {
132 + /* */ }
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
1 +/* global styles */
2 +.sunlight-container {
3 + clear: both !important;
4 + position: relative !important;
5 + margin: 10px 0 !important;
6 +}
7 +.sunlight-code-container {
8 + clear: both !important;
9 + position: relative !important;
10 + border: none;
11 + border-color: #626262 !important;
12 + background-color: #262626 !important;
13 +}
14 +.sunlight-highlighted, .sunlight-container, .sunlight-container textarea {
15 + font-family: Consolas, Inconsolata, Monaco, "Courier New" !important;
16 + font-size: 12px !important;
17 + line-height: 15px !important;
18 +}
19 +.sunlight-highlighted, .sunlight-container textarea {
20 + color: #FFFFFF !important;
21 + margin: 0 !important;
22 +}
23 +.sunlight-container textarea {
24 + padding-left: 0 !important;
25 + margin-left: 0 !important;
26 + margin-right: 0 !important;
27 + padding-right: 0 !important;
28 +}
29 +.sunlight-code-container > .sunlight-highlighted {
30 + white-space: pre;
31 + overflow-x: auto;
32 + overflow-y: hidden; /* ie requires this wtf? */
33 +}
34 +.sunlight-highlighted {
35 + z-index: 1;
36 + position: relative;
37 +}
38 +.sunlight-highlighted * {
39 + background: transparent;
40 +}
41 +.sunlight-line-number-margin {
42 + float: left !important;
43 + margin-right: 5px !important;
44 + margin-top: 0 !important;
45 + margin-bottom: 0 !important;
46 + padding: 0 !important;
47 + padding-right: 4px !important;
48 + padding-left: 4px !important;
49 + border-right: 1px solid #9A9A9A !important;
50 + background-color: #3E3E3E !important;
51 + color: #9A9A9A !important;
52 + text-align: right !important;
53 + position: relative;
54 + z-index: 3;
55 +}
56 +.sunlight-highlighted a, .sunlight-line-number-margin a {
57 + border: none !important;
58 + text-decoration: none !important;
59 + font-style: normal !important;
60 + padding: 0 !important;
61 +}
62 +.sunlight-line-number-margin a {
63 + color: inherit !important;
64 +}
65 +.sunlight-line-highlight-overlay {
66 + position: absolute;
67 + top: 0;
68 + left: 0;
69 + width: 100%;
70 + z-index: 0;
71 +}
72 +.sunlight-line-highlight-overlay div {
73 + height: 15px;
74 + width: 100%;
75 +}
76 +.sunlight-line-highlight-overlay .sunlight-line-highlight-active {
77 + background-color: #4B4B4B;
78 +}
79 +
80 +/* menu */
81 +.sunlight-menu {
82 + background-color: #FFFFCC;
83 + color: #000000;
84 +}
85 +.sunlight-menu ul {
86 + margin: 0 !important;
87 + padding: 0 !important;
88 + list-style-type: none !important;
89 +}
90 +.sunlight-menu li {
91 + float: right !important;
92 + margin-left: 5px !important;
93 +}
94 +.sunlight-menu a, .sunlight-menu img {
95 + color: #000099 !important;
96 + text-decoration: none !important;
97 + border: none !important;
98 +}
99 +
100 +
101 +
102 +
103 +.sunlight-string,
104 +.sunlight-char,
105 +.sunlight-heredoc,
106 +.sunlight-heredocDeclaration,
107 +.sunlight-nowdoc,
108 +.sunlight-longString,
109 +.sunlight-rawString,
110 +.sunlight-binaryString,
111 +.sunlight-verbatimString,
112 +.sunlight-rawLongString,
113 +.sunlight-binaryLongString,
114 +.sunlight-diff .sunlight-added {
115 + color: #55EB54 !important;
116 +}
117 +.sunlight-operator,
118 +.sunlight-punctuation,
119 +.sunlight-delimiter {
120 + color: #B1EDEC !important;
121 +}
122 +.sunlight-ident,
123 +.sunlight-diff .sunlight-unchanged {
124 + color: #E0E0E0 !important;
125 + font-weight: bold !important;
126 +}
127 +.sunlight-comment,
128 +.sunlight-xmlDocCommentContent,
129 +.sunlight-nginx .sunlight-ssiCommand,
130 +.sunlight-sln .sunlight-formatDeclaration,
131 +.sunlight-diff .sunlight-mergeHeader,
132 +.sunlight-diff .sunlight-noNewLine {
133 + color: #787D31 !important;
134 +}
135 +.sunlight-number,
136 +.sunlight-cdata,
137 +.sunlight-guid,
138 +.sunlight-diff .sunlight-modified {
139 + color: #F7BA7E !important;
140 + font-weight: bold !important;
141 +}
142 +.sunlight-named-ident,
143 +.sunlight-xml .sunlight-attribute,
144 +.sunlight-constant,
145 +.sunlight-javascript .sunlight-globalVariable,
146 +.sunlight-globalObject,
147 +.sunlight-css .sunlight-id,
148 +.sunlight-python .sunlight-attribute,
149 +.sunlight-nginx .sunlight-context,
150 +.sunlight-httpd .sunlight-context,
151 +.sunlight-lisp .sunlight-declarationSpecifier,
152 +.sunlight-erlang .sunlight-userDefinedFunction,
153 +.sunlight-diff .sunlight-removed {
154 + color: #FBBDEE !important;
155 + font-weight: bold !important;
156 +}
157 +.sunlight-keyword,
158 +.sunlight-languageConstruct,
159 +.sunlight-specialOperator,
160 +.sunlight-xml .sunlight-tagName,
161 +.sunlight-xml .sunlight-operator,
162 +.sunlight-bash .sunlight-command,
163 +.sunlight-erlang .sunlight-moduleAttribute {
164 + color: #A3CCF7 !important;
165 + font-weight: bold !important;
166 +}
167 +.sunlight-shortOpenTag,
168 +.sunlight-openTag,
169 +.sunlight-closeTag,
170 +.sunlight-xmlOpenTag,
171 +.sunlight-xmlCloseTag,
172 +.sunlight-aspOpenTag,
173 +.sunlight-aspCloseTag,
174 +.sunlight-label,
175 +.sunlight-css .sunlight-importantFlag {
176 + background-color: #7373C1 !important;
177 +}
178 +.sunlight-content {
179 + color: #FFFFFF !important;
180 + font-weight: bold !important;
181 +}
182 +.sunlight-function,
183 +.sunlight-globalFunction,
184 +.sunlight-objective-c .sunlight-messageDestination,
185 +.sunlight-ruby .sunlight-specialFunction,
186 +.sunlight-6502asm .sunlight-illegalOpcode,
187 +.sunlight-powershell .sunlight-switch,
188 +.sunlight-lisp .sunlight-macro,
189 +.sunlight-lisp .sunlight-specialForm,
190 +.sunlight-lisp .sunlight-type,
191 +.sunlight-sln .sunlight-sectionName,
192 +.sunlight-diff .sunlight-header {
193 + color: #C8BBF1 !important;
194 + font-weight: bold !important;
195 +}
196 +.sunlight-variable,
197 +.sunlight-environmentVariable,
198 +.sunlight-specialVariable,
199 +.sunlight-objective-c .sunlight-messageArgumentName,
200 +.sunlight-lisp .sunlight-globalVariable,
201 +.sunlight-ruby .sunlight-globalVariable,
202 +.sunlight-ruby .sunlight-instanceVariable {
203 + color: #F5E5B0 !important;
204 + font-weight: bold !important;
205 +}
206 +.sunlight-regexLiteral,
207 +.sunlight-lisp .sunlight-operator,
208 +.sunlight-6502asm .sunlight-pseudoOp,
209 +.sunlight-erlang .sunlight-macro,
210 +.sunlight-diff .sunlight-rangeInfo {
211 + color: #E0F16A !important;
212 +}
213 +.sunlight-specialVariable {
214 + font-style: italic !important;
215 + font-weight: bold !important;
216 +}
217 +.sunlight-csharp .sunlight-pragma,
218 +.sunlight-preprocessorDirective,
219 +.sunlight-vb .sunlight-compilerDirective {
220 + color: #666363 !important;
221 + font-style: italic !important;
222 +}
223 +.sunlight-xmlDocCommentMeta,
224 +.sunlight-java .sunlight-annotation,
225 +.sunlight-scala .sunlight-annotation,
226 +.sunlight-docComment {
227 + color: #666363 !important;
228 +}
229 +.sunlight-quotedIdent,
230 +.sunlight-ruby .sunlight-subshellCommand,
231 +.sunlight-lisp .sunlight-keywordArgument,
232 +.sunlight-haskell .sunlight-infixOperator,
233 +.sunlight-erlang .sunlight-quotedAtom {
234 + color: #F8CA16 !important;
235 +}
236 +
237 +
238 +
239 +
240 +/* html/xml */
241 +.sunlight-xml .sunlight-tagName,
242 +.sunlight-xml .sunlight-operator,
243 +.sunlight-xml .sunlight-attribute {
244 + font-weight: normal !important;
245 +}
246 +.sunlight-doctype {
247 + color: #DEB9B2 !important;
248 + font-style: italic !important;
249 +}
250 +.sunlight-xml .sunlight-entity {
251 + background-color: #E6E585 !important;
252 + color: #000000 !important;
253 +}
254 +
255 +/* javascript */
256 +.sunlight-javascript .sunlight-reservedWord {
257 + font-style: italic !important;
258 +}
259 +
260 +/* css */
261 +.sunlight-css .sunlight-element {
262 + color: #E9EE97 !important;
263 +}
264 +.sunlight-css .sunlight-microsoftFilterPrefix {
265 + color: #C9FF9F !important;
266 +}
267 +.sunlight-css .sunlight-rule {
268 + color: #0099FF !important;
269 +}
270 +.sunlight-css .sunlight-class {
271 + color: #E78282 !important;
272 +}
273 +.sunlight-css .sunlight-pseudoClass, .sunlight-css .sunlight-pseudoElement {
274 + color: #73D693 !important;
275 +}
276 +
277 +/* bash */
278 +.sunlight-bash .sunlight-hashBang {
279 + color: #FFFF00 !important;
280 +}
281 +
282 +.sunlight-bash .sunlight-verbatimCommand {
283 + color: #BBA4EE !important;
284 +}
285 +.sunlight-bash .sunlight-variable,
286 +.sunlight-bash .sunlight-specialVariable {
287 + color: #ED8585 !important;
288 +}
289 +
290 +/* python */
291 +.sunlight-python .sunlight-specialMethod {
292 + font-weight: bold !important;
293 + color: #B0A3C2;
294 +}
295 +
296 +/* ruby */
297 +.sunlight-ruby .sunlight-symbol {
298 + font-weight: bold !important;
299 + color: #90EEA2 !important;
300 +}
301 +
302 +/* brainfuck */
303 +.sunlight-brainfuck {
304 + font-weight: bold !important;
305 + color: #000000 !important;
306 +}
307 +.sunlight-brainfuck .sunlight-increment {
308 + background-color: #FF9900 !important;
309 +}
310 +.sunlight-brainfuck .sunlight-decrement {
311 + background-color: #FF99FF !important;
312 +}
313 +.sunlight-brainfuck .sunlight-incrementPointer {
314 + background-color: #FFFF99 !important;
315 +}
316 +.sunlight-brainfuck .sunlight-decrementPointer {
317 + background-color: #66CCFF !important;
318 +}
319 +.sunlight-brainfuck .sunlight-read {
320 + background-color: #FFFFFF !important;
321 +}
322 +.sunlight-brainfuck .sunlight-write {
323 + background-color: #99FF99 !important;
324 +}
325 +.sunlight-brainfuck .sunlight-openLoop, .sunlight-brainfuck .sunlight-closeLoop {
326 + background-color: #FFFFFF !important;
327 +}
328 +
329 +/* 6502 asm */
330 +.sunlight-6502asm .sunlight-label {
331 + background: none !important;
332 + color: #FFFFFF !important;
333 + text-decoration: underline !important;
334 +}
335 +
336 +/* lisp */
337 +.sunlight-lisp .sunlight-macro {
338 + font-style: italic !important;
339 +}
340 +
341 +/* erlang */
342 +.sunlight-erlang .sunlight-atom {
343 + color: #FFFFFF !important;
344 + font-weight: bold !important;
345 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/* global styles */
2 +.sunlight-container {
3 + clear: both !important;
4 + position: relative !important;
5 + margin: 10px 0 !important;
6 +}
7 +.sunlight-code-container {
8 + clear: both !important;
9 + position: relative !important;
10 + border: none;
11 + border-color: #969696 !important;
12 + background-color: #FFFFFF !important;
13 +}
14 +.sunlight-highlighted, .sunlight-container, .sunlight-container textarea {
15 + font-family: Consolas, Inconsolata, Monaco, "Courier New" !important;
16 + font-size: 12px !important;
17 + line-height: 15px !important;
18 +}
19 +.sunlight-highlighted, .sunlight-container textarea {
20 + color: #000000 !important;
21 + margin: 0 !important;
22 +}
23 +.sunlight-container textarea {
24 + padding-left: 0 !important;
25 + margin-left: 0 !important;
26 + margin-right: 0 !important;
27 + padding-right: 0 !important;
28 +}
29 +.sunlight-code-container > .sunlight-highlighted {
30 + white-space: pre;
31 + overflow-x: auto;
32 + overflow-y: hidden; /* ie requires this wtf? */
33 +}
34 +.sunlight-highlighted {
35 + z-index: 1;
36 + position: relative;
37 +}
38 +.sunlight-highlighted * {
39 + background: transparent;
40 +}
41 +.sunlight-line-number-margin {
42 + float: left !important;
43 + margin-right: 5px !important;
44 + margin-top: 0 !important;
45 + margin-bottom: 0 !important;
46 + padding: 0 !important;
47 + padding-right: 4px !important;
48 + padding-left: 4px !important;
49 + border-right: 1px solid #CCCCCC !important;
50 + background-color: #EEEEEE !important;
51 + color: #848484 !important;
52 + text-align: right !important;
53 + position: relative;
54 + z-index: 3;
55 +}
56 +.sunlight-highlighted a, .sunlight-line-number-margin a {
57 + border: none !important;
58 + text-decoration: none !important;
59 + font-weight: normal !important;
60 + font-style: normal !important;
61 + padding: 0 !important;
62 +}
63 +.sunlight-line-number-margin a {
64 + color: inherit !important;
65 +}
66 +.sunlight-line-highlight-overlay {
67 + position: absolute;
68 + top: 0;
69 + left: 0;
70 + width: 100%;
71 + z-index: 0;
72 +}
73 +.sunlight-line-highlight-overlay div {
74 + height: 15px;
75 + width: 100%;
76 +}
77 +.sunlight-line-highlight-overlay .sunlight-line-highlight-active {
78 + background-color: #E7FCFA;
79 +}
80 +
81 +/* menu */
82 +.sunlight-menu {
83 + background-color: #FFFFCC;
84 + color: #000000;
85 +}
86 +.sunlight-menu ul {
87 + margin: 0 !important;
88 + padding: 0 !important;
89 + list-style-type: none !important;
90 +}
91 +.sunlight-menu li {
92 + float: right !important;
93 + margin-left: 5px !important;
94 +}
95 +.sunlight-menu a, .sunlight-menu img {
96 + color: #000099 !important;
97 + text-decoration: none !important;
98 + border: none !important;
99 +}
100 +
101 +
102 +
103 +
104 +.sunlight-string,
105 +.sunlight-char,
106 +.sunlight-heredoc,
107 +.sunlight-heredocDeclaration,
108 +.sunlight-nowdoc,
109 +.sunlight-longString,
110 +.sunlight-rawString,
111 +.sunlight-binaryString,
112 +.sunlight-rawLongString,
113 +.sunlight-binaryLongString,
114 +.sunlight-verbatimString,
115 +.sunlight-diff .sunlight-removed {
116 + color: #990000 !important;
117 +}
118 +
119 +.sunlight-ident,
120 +.sunlight-operator,
121 +.sunlight-punctuation,
122 +.sunlight-delimiter,
123 +.sunlight-diff .sunlight-unchanged {
124 + color: #000000 !important;
125 +}
126 +
127 +.sunlight-comment,
128 +.sunlight-xmlDocCommentContent,
129 +.sunlight-nginx .sunlight-ssiCommand,
130 +.sunlight-sln .sunlight-formatDeclaration,
131 +.sunlight-diff .sunlight-added {
132 + color: #009900 !important;
133 +}
134 +.sunlight-number,
135 +.sunlight-guid,
136 +.sunlight-cdata {
137 + color: #CC6600 !important;
138 +}
139 +
140 +.sunlight-named-ident,
141 +.sunlight-constant,
142 +.sunlight-javascript .sunlight-globalVariable,
143 +.sunlight-globalObject,
144 +.sunlight-python .sunlight-attribute,
145 +.sunlight-nginx .sunlight-context,
146 +.sunlight-httpd .sunlight-context,
147 +.sunlight-haskell .sunlight-class,
148 +.sunlight-haskell .sunlight-type,
149 +.sunlight-lisp .sunlight-declarationSpecifier,
150 +.sunlight-erlang .sunlight-userDefinedFunction,
151 +.sunlight-diff .sunlight-header {
152 + color: #2B91AF !important;
153 +}
154 +.sunlight-keyword,
155 +.sunlight-languageConstruct,
156 +.sunlight-css
157 +.sunlight-element,
158 +.sunlight-bash .sunlight-command,
159 +.sunlight-specialOperator,
160 +.sunlight-erlang .sunlight-moduleAttribute,
161 +.sunlight-xml .sunlight-tagName,
162 +.sunlight-xml .sunlight-operator,
163 +.sunlight-diff .sunlight-modified {
164 + color: #0000FF !important;
165 +}
166 +.sunlight-shortOpenTag,
167 +.sunlight-openTag,
168 +.sunlight-closeTag,
169 +.sunlight-xmlOpenTag,
170 +.sunlight-xmlCloseTag,
171 +.sunlight-aspOpenTag,
172 +.sunlight-aspCloseTag,
173 +.sunlight-label,
174 +.sunlight-css .sunlight-importantFlag {
175 + background-color: #FFFF99 !important;
176 + color: #000000 !important;
177 +}
178 +.sunlight-function,
179 +.sunlight-globalFunction,
180 +.sunlight-ruby .sunlight-specialFunction,
181 +.sunlight-objective-c .sunlight-messageDestination,
182 +.sunlight-6502asm .sunlight-illegalOpcode,
183 +.sunlight-powershell .sunlight-switch,
184 +.sunlight-lisp .sunlight-macro,
185 +.sunlight-lisp .sunlight-specialForm,
186 +.sunlight-lisp .sunlight-type,
187 +.sunlight-sln .sunlight-sectionName,
188 +.sunlight-diff .sunlight-rangeInfo {
189 + color: #B069AF !important;
190 +}
191 +
192 +.sunlight-variable,
193 +.sunlight-specialVariable,
194 +.sunlight-environmentVariable,
195 +.sunlight-objective-c .sunlight-messageArgumentName,
196 +.sunlight-lisp .sunlight-globalVariable,
197 +.sunlight-ruby .sunlight-globalVariable,
198 +.sunlight-ruby .sunlight-instanceVariable,
199 +.sunlight-sln .sunlight-operator {
200 + color: #325484 !important;
201 +}
202 +.sunlight-regexLiteral,
203 +.sunlight-lisp .sunlight-operator,
204 +.sunlight-6502asm .sunlight-pseudoOp,
205 +.sunlight-erlang .sunlight-macro {
206 + color: #FF00B2 !important;
207 +}
208 +.sunlight-specialVariable {
209 + font-style: italic !important;
210 + font-weight: bold !important;
211 +}
212 +.sunlight-csharp .sunlight-pragma,
213 +.sunlight-preprocessorDirective,
214 +.sunlight-vb .sunlight-compilerDirective,
215 +.sunlight-diff .sunlight-mergeHeader,
216 +.sunlight-diff .sunlight-noNewLine {
217 + color: #999999 !important;
218 + font-style: italic !important;
219 +}
220 +.sunlight-xmlDocCommentMeta,
221 +.sunlight-java .sunlight-annotation,
222 +.sunlight-scala .sunlight-annotation,
223 +.sunlight-docComment {
224 + color: #808080 !important;
225 +}
226 +.sunlight-quotedIdent,
227 +.sunlight-ruby .sunlight-subshellCommand,
228 +.sunlight-lisp .sunlight-keywordArgument,
229 +.sunlight-haskell .sunlight-infixOperator,
230 +.sunlight-erlang .sunlight-quotedAtom {
231 + color: #999900 !important;
232 +}
233 +
234 +
235 +
236 +/* xml */
237 +.sunlight-xml .sunlight-string {
238 + color: #990099 !important;
239 +}
240 +.sunlight-xml .sunlight-attribute {
241 + color: #FF0000 !important;
242 +}
243 +.sunlight-xml .sunlight-entity {
244 + background-color: #EEEEEE !important;
245 + color: #000000 !important;
246 + border: 1px solid #000000 !important;
247 +}
248 +.sunlight-xml .sunlight-doctype {
249 + color: #2B91AF !important;
250 +}
251 +
252 +/* javascript */
253 +.sunlight-javascript .sunlight-reservedWord {
254 + font-style: italic !important;
255 +}
256 +
257 +/* css */
258 +.sunlight-css .sunlight-microsoftFilterPrefix {
259 + color: #FF00FF !important;
260 +}
261 +.sunlight-css .sunlight-rule {
262 + color: #0099FF !important;
263 +}
264 +.sunlight-css .sunlight-keyword {
265 + color: #4E65B8 !important;
266 +}
267 +.sunlight-css .sunlight-class {
268 + color: #FF0000 !important;
269 +}
270 +.sunlight-css .sunlight-id {
271 + color: #8A8E13 !important;
272 +}
273 +.sunlight-css .sunlight-pseudoClass,
274 +.sunlight-css .sunlight-pseudoElement {
275 + color: #368B87 !important;
276 +}
277 +
278 +/* bash */
279 +.sunlight-bash .sunlight-hashBang {
280 + color: #3D97F5 !important;
281 +}
282 +.sunlight-bash .sunlight-verbatimCommand {
283 + color: #999900 !important;
284 +}
285 +.sunlight-bash .sunlight-variable,
286 +.sunlight-bash .sunlight-specialVariable {
287 + color: #FF0000 !important;
288 +}
289 +
290 +/* python */
291 +.sunlight-python .sunlight-specialMethod {
292 + font-weight: bold !important;
293 + color: #A07DD3;
294 +}
295 +
296 +/* ruby */
297 +.sunlight-ruby .sunlight-symbol {
298 + font-weight: bold !important;
299 + color: #ED7272 !important;
300 +}
301 +
302 +/* brainfuck */
303 +.sunlight-brainfuck {
304 + font-weight: bold !important;
305 + color: #000000 !important;
306 +}
307 +.sunlight-brainfuck .sunlight-increment {
308 + background-color: #FF9900 !important;
309 +}
310 +.sunlight-brainfuck .sunlight-decrement {
311 + background-color: #FF99FF !important;
312 +}
313 +.sunlight-brainfuck .sunlight-incrementPointer {
314 + background-color: #FFFF99 !important;
315 +}
316 +.sunlight-brainfuck .sunlight-decrementPointer {
317 + background-color: #66CCFF !important;
318 +}
319 +.sunlight-brainfuck .sunlight-read {
320 + background-color: #FFFFFF !important;
321 +}
322 +.sunlight-brainfuck .sunlight-write {
323 + background-color: #99FF99 !important;
324 +}
325 +.sunlight-brainfuck .sunlight-openLoop, .sunlight-brainfuck .sunlight-closeLoop {
326 + background-color: #FFFFFF !important;
327 +}
328 +
329 +/* 6502 asm */
330 +.sunlight-6502asm .sunlight-label {
331 + font-weight: bold !important;
332 + color: #000000 !important;
333 + background: none !important;
334 +}
335 +
336 +/* lisp */
337 +.sunlight-lisp .sunlight-macro {
338 + font-style: italic !important;
339 +}
340 +
341 +/* erlang */
342 +.sunlight-erlang .sunlight-atom {
343 + font-weight: bold !important;
344 +}
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +<!DOCTYPE html>
2 +
3 +<html lang="en">
4 +<head>
5 + <meta charset="utf-8">
6 + <title>sequelize-pg-generator Source: template/index.js</title>
7 +
8 + <!--[if lt IE 9]>
9 + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
10 + <![endif]-->
11 + <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
12 +
13 + <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
14 +
15 +</head>
16 +
17 +<body>
18 +<div class="container-fluid">
19 + <div class="navbar navbar-fixed-top navbar-inverse">
20 + <div class="navbar-inner">
21 + <a class="brand" href="index.html">sequelize-pg-generator</a>
22 + <ul class="nav">
23 +
24 + <li class="dropdown">
25 + <a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
26 + class="caret"></b></a>
27 +
28 + <ul class="dropdown-menu ">
29 +
30 + <li>
31 + <a href="module-lib_index.html">lib/index</a>
32 + </li>
33 +
34 + <li>
35 + <a href="module-path_to_model.html">path/to/model</a>
36 + </li>
37 +
38 +
39 + </ul>
40 + </li>
41 +
42 + <li class="dropdown">
43 + <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
44 + class="caret"></b></a>
45 +
46 + <ul class="dropdown-menu ">
47 +
48 + <li>
49 + <a href="GeneratorUtil.html">GeneratorUtil</a>
50 + </li>
51 +
52 +
53 + </ul>
54 + </li>
55 +
56 + </ul>
57 + </div>
58 + </div>
59 +
60 + <div class="row-fluid">
61 +
62 +
63 + <div class="span12">
64 +
65 + <div id="main">
66 +
67 +
68 +
69 + <h1 class="page-title">Source: template/index.js</h1>
70 +
71 +<section>
72 + <article>
73 + <pre
74 + class="sunlight-highlight-javascript linenums">/**
75 + * This file is auto generated by sequelize-pg-generator.
76 + * @module path/to/model
77 + * @author Özüm Eldoğan
78 + */
79 +
80 +/*jslint node: true, stupid: true, nomen: true */
81 +"use strict";
82 +
83 +var Sequelize = require('sequelize'),
84 + fs = require('fs'),
85 + path = require('path'),
86 + util = require('util'),
87 + models = {},
88 + relationships = {},
89 + modelsPath = '',
90 + definitionDir = 'definition-files',
91 + definitionDirCustom = definitionDir + '-custom',
92 + debug = false,
93 + debugFD = '',
94 + sequelize = null;
95 +
96 +/**
97 + * Requires given npm module file and defines sequelize module according to exported object from that module.
98 + * @private
99 + * @param {string} file - Location of the npm module file which contains model definition.
100 + */
101 +function defineModel(file) {
102 + var object = require(file),
103 + options = object.options || {},
104 + modelName = object.modelName;
105 +
106 + fs.writeSync(debugFD, 'var ' + modelName + ' = Sequelize.define("' + modelName + '",\n' + util.inspect(object.attributes) + ',\n' + util.inspect(options, {depth: null}) + ');\n\n\n');
107 +
108 + models[modelName] = sequelize.define(modelName, object.attributes, options);
109 + if (object.relations !== undefined) {
110 + relationships[modelName] = object.relations;
111 + }
112 +}
113 +
114 +
115 +/**
116 + * Define 'hasMany' and 'belongsTo' relations.
117 + * @private
118 + * @param {string} modelName - Name of the model
119 + * @param {string} relationType - Type of the relation 'hasMany' or 'belongsTo'
120 + * @param {string} targetModelName - Name of the target model which this relation related to.
121 + * @param {Object} options - Sequelize options of relation.
122 + */
123 +function defineRelation(modelName, relationType, targetModelName, options) {
124 + fs.writeSync(debugFD, modelName + '.' + relationType + '(' + targetModelName + ', ' + util.inspect(options, {depth: null}) + ');\n\n');
125 + models[modelName][relationType](models[targetModelName], options); // account.hasMany(contact, {...})
126 +}
127 +
128 +
129 +/**
130 + * Generates list of definition files by looking given modelsPath directory. It traverses 'definition-files'
131 + * and 'definition-files-custom' directories to generate the list. Files in 'definition-files' will be skipped
132 + * if a file with same name is found in 'definition-files-custom' directory.
133 + * @private
134 + * @returns {Array}
135 + * @example
136 + * var list = getFileList('../model'); // ['./definition-files-custom/public_cart.js', './definition-files/public_account.js]
137 + */
138 +function getFileList() {
139 + var i, file, isOverridden = {}, files = [], customFiles, baseFiles;
140 + baseFiles = fs.readdirSync(path.join(modelsPath, definitionDir));
141 + customFiles = fs.readdirSync(path.join(modelsPath, definitionDirCustom));
142 +
143 + for (i = 0; i &lt; customFiles.length; i = i + 1) {
144 + file = customFiles[i];
145 + if (file.match(/\.js$/)) {
146 + isOverridden[file] = true;
147 + files.push('./' + path.join(definitionDirCustom, file));
148 + }
149 + }
150 +
151 + for (i = 0; i &lt; baseFiles.length; i = i + 1) {
152 + file = baseFiles[i];
153 + if (!isOverridden[file] &amp;&amp; file.match(/\.js$/)) {
154 + files.push('./' + path.join(definitionDir, file));
155 + }
156 + }
157 + return files;
158 +}
159 +
160 +
161 +/**
162 + * Iterates all relations and executes given callback on them. Callback is passed
163 + * ({string} modelName, {string} relationType, {string} targetModelName, {Object} relationOptions)
164 + * @private
165 + * @param {function} callback - Callback function.
166 + * @returns {Array}
167 + */
168 +function processAllRelations(callback) {
169 + var i, modelName, relation, relations, result = [];
170 + for (modelName in relationships) {
171 + if (relationships.hasOwnProperty(modelName)) {
172 + relations = relationships[modelName];
173 + for (i = 0; i &lt; relations.length; i = i + 1) {
174 + relation = relations[i];
175 + result.push(callback(modelName, relation.type, relation.model, relation.details));
176 + }
177 + }
178 + }
179 + return result;
180 +}
181 +
182 +
183 +/**
184 + * Initializes models.
185 + * @private
186 + */
187 +function init() {
188 + var debugFile = path.join(__dirname, 'debug.js');
189 + if (fs.existsSync(debugFile)) { fs.unlinkSync(debugFile); }
190 + debugFD = fs.openSync(debugFile, 'a');
191 +
192 + getFileList(modelsPath).forEach(defineModel);
193 + processAllRelations(defineRelation);
194 +
195 + fs.closeSync(debugFD);
196 +}
197 +
198 +module.exports = {};
199 +
200 +/**
201 + * Sets up sequelize models based on model files in given directory for given database details.
202 + * @param {string} database - Name of the database to connect
203 + * @param {string} username - Username of the database
204 + * @param {string} password - Password of the database
205 + * @param {Object} obj - Object to pass new Sequelize() function. See Sequelize for details.
206 + * @example
207 + * var orm = require('../model');
208 + * orm.setup('path/to/model', 'database', 'user', 'password', {
209 + * host: '127.0.0.1',
210 + * logging: false,
211 + * native: true
212 + * });
213 + */
214 +module.exports.setup = function (database, username, password, obj) {
215 + if (typeof obj !== 'object') { obj = {}; }
216 + if (obj.dialect === undefined || obj.dialect === null) { obj.dialect = 'postgres'; }
217 +
218 + if (arguments.length === 2) {
219 + sequelize = new Sequelize(database, username);
220 + } else if (arguments.length === 3) {
221 + sequelize = new Sequelize(database, username, password);
222 + } else if (arguments.length === 4) {
223 + sequelize = new Sequelize(database, username, password, obj);
224 + }
225 + modelsPath = __dirname;
226 + init();
227 +};
228 +
229 +/**
230 + * Returns requested model with given name.
231 + * @param {string} name - Model name
232 + * @returns {object} - Sequelize model
233 + */
234 +module.exports.model = function (name) {
235 + return models[name];
236 +};
237 +
238 +/**
239 + * Returns Sequelize object.
240 + * @returns {Sequelize} - Sequelize object
241 + */
242 +module.exports.Sequelize = function () {
243 + return Sequelize;
244 +};
245 +
246 +/**
247 + * Returns sequelize instance.
248 + * @returns {Sequelize} - sequelize instance
249 + */
250 +module.exports.sequelize = function () {
251 + return sequelize;
252 +};
253 +</pre>
254 + </article>
255 +</section>
256 +
257 +
258 +
259 +
260 +
261 + </div>
262 +
263 + <div class="clearfix"></div>
264 + <footer>
265 +
266 +
267 + <span class="copyright">
268 + sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.
269 + </span>
270 + <br />
271 +
272 + <span class="jsdoc-message">
273 + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.1</a>
274 + on Mon Aug 3rd 2015 using the <a
275 + href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
276 + </span>
277 + </footer>
278 + </div>
279 +
280 +
281 + <br clear="both">
282 + </div>
283 +
284 + </div>
285 + <!--<script src="scripts/sunlight.js"></script>-->
286 + <script src="scripts/docstrap.lib.js"></script>
287 + <script src="scripts/bootstrap-dropdown.js"></script>
288 + <script src="scripts/toc.js"></script>
289 +
290 + <script>
291 + $( function () {
292 + $( "[id*='$']" ).each( function () {
293 + var $this = $( this );
294 +
295 + $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
296 + } );
297 +
298 + $( "#toc" ).toc( {
299 + anchorName : function ( i, heading, prefix ) {
300 + return $( heading ).attr( "id" ) || ( prefix + i );
301 + },
302 + selectors : "h1,h2,h3,h4",
303 + showAndHide : false,
304 + scrollTo : "100px"
305 + } );
306 +
307 + $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
308 + $( "#main span[id^='toc']" ).addClass( "toc-shim" );
309 + $( '.dropdown-toggle' ).dropdown();
310 +// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
311 +
312 + $( ".tutorial-section pre, .readme-section pre" ).each( function () {
313 + var $this = $( this );
314 +
315 + var example = $this.find( "code" );
316 + exampleText = example.html();
317 + var lang = /{@lang (.*?)}/.exec( exampleText );
318 + if ( lang && lang[1] ) {
319 + exampleText = exampleText.replace( lang[0], "" );
320 + example.html( exampleText );
321 + lang = lang[1];
322 + } else {
323 + lang = "javascript";
324 + }
325 +
326 + if ( lang ) {
327 +
328 + $this
329 + .addClass( "sunlight-highlight-" + lang )
330 + .addClass( "linenums" )
331 + .html( example.html() );
332 +
333 + }
334 + } );
335 +
336 + Sunlight.highlightAll( {
337 + lineNumbers : true,
338 + showMenu : true,
339 + enableDoclinks : true
340 + } );
341 + } );
342 + </script>
343 +
344 +
345 +
346 + <!--Navigation and Symbol Display-->
347 +
348 +
349 +
350 + <!--Google Analytics-->
351 +
352 +
353 +</body>
354 +</html>
This diff is collapsed. Click to expand it.
1 +<!DOCTYPE html>
2 +
3 +<html lang="en">
4 +<head>
5 + <meta charset="utf-8">
6 + <title>sequelize-pg-generator Source: template/utils.js</title>
7 +
8 + <!--[if lt IE 9]>
9 + <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
10 + <![endif]-->
11 + <link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
12 +
13 + <link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
14 +
15 +</head>
16 +
17 +<body>
18 +<div class="container-fluid">
19 + <div class="navbar navbar-fixed-top navbar-inverse">
20 + <div class="navbar-inner">
21 + <a class="brand" href="index.html">sequelize-pg-generator</a>
22 + <ul class="nav">
23 +
24 + <li class="dropdown">
25 + <a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b
26 + class="caret"></b></a>
27 +
28 + <ul class="dropdown-menu ">
29 +
30 + <li>
31 + <a href="module-lib_index.html">lib/index</a>
32 + </li>
33 +
34 + <li>
35 + <a href="module-path_to_model.html">path/to/model</a>
36 + </li>
37 +
38 +
39 + </ul>
40 + </li>
41 +
42 + <li class="dropdown">
43 + <a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
44 + class="caret"></b></a>
45 +
46 + <ul class="dropdown-menu ">
47 +
48 + <li>
49 + <a href="GeneratorUtil.html">GeneratorUtil</a>
50 + </li>
51 +
52 +
53 + </ul>
54 + </li>
55 +
56 + </ul>
57 + </div>
58 + </div>
59 +
60 + <div class="row-fluid">
61 +
62 +
63 + <div class="span12">
64 +
65 + <div id="main">
66 +
67 +
68 +
69 + <h1 class="page-title">Source: template/utils.js</h1>
70 +
71 +<section>
72 + <article>
73 + <pre
74 + class="sunlight-highlight-javascript linenums">/**
75 + * Utility methods to modify and customize auto generated models without affecting further auto generations.
76 + * Require this module from model customization scripts located in path/to/model/definitions-files-custom directory.
77 + * @class
78 + * @author Özüm Eldoğan
79 + */
80 +
81 +
82 +/*jslint node: true */
83 +"use strict";
84 +
85 +
86 +/**
87 + * @constructor
88 + * @param model
89 + */
90 +var GeneratorUtil = function (model) {
91 + this.model = model;
92 +};
93 +
94 +
95 +/**
96 + * Searches and returns relation with the given alias. Alias is defined in sequelize options with parameter 'as'
97 + * @method
98 + * @param {string} as - Alias of the relation.
99 + * @returns {Object}
100 + */
101 +GeneratorUtil.prototype.getRelation = function (as) {
102 + var i,
103 + relations = this.model.relations;
104 + for (i = 0; i &lt; relations.length; i = i + 1) {
105 + if (relations[i].details.as === as) {
106 + return relations[i];
107 + }
108 + }
109 +};
110 +
111 +
112 +/**
113 + * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
114 + * @method
115 + * @param {string} name - Name of the attribute.
116 + * @returns {Object}
117 + */
118 +GeneratorUtil.prototype.getAttribute = function (name) {
119 + return this.model.attributes[name];
120 +};
121 +
122 +
123 +/**
124 + * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
125 + * @method
126 + * @param {string} oldName - Name of the attribute which it's name to be changed.
127 + * @param {string} newName - New name of the attribute.
128 + * @throws Will throw error if there is already an attribute with new name exists or attribute with oldName does not exists.
129 + */
130 +GeneratorUtil.prototype.renameAttribute = function (oldName, newName) {
131 + if (this.model.attributes[newName] !== undefined) {
132 + throw new Error('There is already an attribute with the same name ("' + newName + '") in table "' + this.model.modelName + '".');
133 + }
134 + if (this.model.attributes[oldName] === undefined) {
135 + throw new Error('There is no attribute with the name "' + oldName + '". in table "' + this.model.modelName + '".');
136 + }
137 + this.model.attributes[newName] = this.model.attributes[oldName];
138 + delete this.model.attributes[oldName];
139 +};
140 +
141 +
142 +/**
143 + * Creates and returns new object with utility functions.
144 + * @param model
145 + * @returns {GeneratorUtil}
146 + */
147 +module.exports = function (model) {
148 + return new GeneratorUtil(model);
149 +};
150 +
151 +</pre>
152 + </article>
153 +</section>
154 +
155 +
156 +
157 +
158 +
159 + </div>
160 +
161 + <div class="clearfix"></div>
162 + <footer>
163 +
164 +
165 + <span class="copyright">
166 + sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.
167 + </span>
168 + <br />
169 +
170 + <span class="jsdoc-message">
171 + Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0-dev</a>
172 + on Fri Nov 27th 2015 using the <a
173 + href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
174 + </span>
175 + </footer>
176 + </div>
177 +
178 +
179 + <br clear="both">
180 + </div>
181 +
182 + </div>
183 + <!--<script src="scripts/sunlight.js"></script>-->
184 + <script src="scripts/docstrap.lib.js"></script>
185 + <script src="scripts/bootstrap-dropdown.js"></script>
186 + <script src="scripts/toc.js"></script>
187 +
188 + <script>
189 + $( function () {
190 + $( "[id*='$']" ).each( function () {
191 + var $this = $( this );
192 +
193 + $this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
194 + } );
195 +
196 + $( "#toc" ).toc( {
197 + anchorName : function ( i, heading, prefix ) {
198 + return $( heading ).attr( "id" ) || ( prefix + i );
199 + },
200 + selectors : "h1,h2,h3,h4",
201 + showAndHide : false,
202 + scrollTo : "100px"
203 + } );
204 +
205 + $( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
206 + $( "#main span[id^='toc']" ).addClass( "toc-shim" );
207 + $( '.dropdown-toggle' ).dropdown();
208 +// $( ".tutorial-section pre, .readme-section pre" ).addClass( "sunlight-highlight-javascript" ).addClass( "linenums" );
209 +
210 + $( ".tutorial-section pre, .readme-section pre" ).each( function () {
211 + var $this = $( this );
212 +
213 + var example = $this.find( "code" );
214 + exampleText = example.html();
215 + var lang = /{@lang (.*?)}/.exec( exampleText );
216 + if ( lang && lang[1] ) {
217 + exampleText = exampleText.replace( lang[0], "" );
218 + example.html( exampleText );
219 + lang = lang[1];
220 + } else {
221 + lang = "javascript";
222 + }
223 +
224 + if ( lang ) {
225 +
226 + $this
227 + .addClass( "sunlight-highlight-" + lang )
228 + .addClass( "linenums" )
229 + .html( example.html() );
230 +
231 + }
232 + } );
233 +
234 + Sunlight.highlightAll( {
235 + lineNumbers : true,
236 + showMenu : true,
237 + enableDoclinks : true
238 + } );
239 + } );
240 + </script>
241 +
242 +
243 +
244 + <!--Navigation and Symbol Display-->
245 +
246 +
247 +
248 + <!--Google Analytics-->
249 +
250 +
251 +</body>
252 +</html>
1 +{
2 + "opts": {
3 + "template": "node_modules/ink-docstrap/template",
4 + "encoding": "utf8",
5 + "destination": "./doc/",
6 + "recurse": true,
7 + "private": false
8 + },
9 + "tags": {
10 + "allowUnknownTags": true
11 + },
12 + "source": {
13 + "include": ["lib","template"],
14 + "includePattern": ".+\\.js(doc)?$",
15 + "excludePattern": "(^|\\/|\\\\)_"
16 + },
17 + "plugins" : ["plugins/markdown"],
18 + "i18n": {
19 + "locale": "<en_US|tr_TR>",
20 + "extension": ".js"
21 + },
22 + "templates" : {
23 + "cleverLinks" : false,
24 + "monospaceLinks" : false,
25 + "dateFormat" : "ddd MMM Do YYYY",
26 + "outputSourceFiles" : true,
27 + "outputSourcePath" : true,
28 + "systemName" : "sequelize-pg-generator",
29 + "footer" : "",
30 + "copyright" : "sequelize-pg-generator Copyright © 2014 Özüm Eldoğan.",
31 + "navType" : "vertical",
32 + "theme" : "cerulean",
33 + "linenums" : true,
34 + "collapseSymbols" : false,
35 + "inverseNav" : true,
36 + "highlightTutorialCode" : true
37 + },
38 + "markdown" : {
39 + "parser" : "gfm",
40 + "hardwrap" : true
41 + }
42 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * @private
3 + */
4 +/*jslint node: true, nomen: true, regexp: true */
5 +"use strict";
6 +
7 +if (!String.prototype.quote) {
8 + // oop version - no dependencies
9 + String.prototype.quote = (function () {
10 + // prepare fallback
11 + // ----------------
12 + // backslash escape double quotes and backslashes
13 + var escp_regex = /[\\"]/g,
14 + escp_callback = '\\$&',
15 + // escape control characters
16 + ctrl_map = {
17 + '\b': '\\b', // backspace
18 + '\t': '\\t', // tab
19 + '\n': '\\n', // new line
20 + '\f': '\\f', // form feed
21 + '\r': '\\r' // carriage return
22 + },
23 + // don't rely on `Object.keys(ctrl_map).join('')`
24 + ctrl_regex = new RegExp('[\b\t\n\f\r]', 'g'),
25 + ctrl_callback = function (match) {
26 + return ctrl_map[match];
27 + },
28 + // hex-escape, spare out control characters and ASCII printables
29 + // [0-7,11,14-31,127-255]
30 + xhex_regex = /[\x00-\x07\x0B\x0E-\x1F\x7F-\xFF]/g,
31 + xhex_callback = function (match, char_code) {
32 + char_code = match.charCodeAt(0);
33 + return '\\x' + (char_code < 16 ? '0' : '') + char_code;
34 + },
35 + // hex-escape all others
36 + uhex_regex = /[\u0100-\uFFFF]/g,
37 + uhex_callback = function (match, char_code) {
38 + char_code = match.charCodeAt(0);
39 + return '\\u' + (char_code < 4096 ? '0' : '') + char_code;
40 + },
41 + // delegate to native `JSON.stringify` if available
42 + stringify = typeof JSON !== 'undefined' && JSON.stringify;
43 +
44 + // return actual polyfill
45 + // ----------------------
46 + return function () {
47 + var self = this; // promote compression
48 + if (self === null) { throw new TypeError('can\'t convert ' + self + ' to object'); }
49 + if (stringify) { return stringify(self); }
50 + return '"' + self
51 + .replace(escp_regex, escp_callback)
52 + .replace(ctrl_regex, ctrl_callback)
53 + .replace(xhex_regex, xhex_callback)
54 + .replace(uhex_regex, uhex_callback) + '"';
55 + };
56 + }());
57 +
58 + // generic version - requires Function#bind
59 + String.quote = Function.call.bind(''.quote);
60 +}
...\ No newline at end of file ...\ No newline at end of file
1 +#!/usr/bin/env node
2 +
3 +/*jslint node: true */
4 +"use strict";
5 +
6 +var program = require('commander'),
7 + generator = require('../index.js'),
8 + version = require('../../package.json').version,
9 + options = {};
10 +
11 +/**
12 + * Parses CSV and returns as a list.
13 + * @private
14 + * @param {string} val - CSV values.
15 + * @returns {Array}
16 + */
17 +function list(val) {
18 + return val.split(',');
19 +}
20 +
21 +
22 +// Define options, help text
23 +program
24 + .version(version)
25 + .option('-h, --host [host]', 'IP address or host name of the database server')
26 + .option(' --port [port]', 'Port of database server to connect')
27 + .option('-d, --database [database]', 'Database name')
28 + .option('-u, --user [user]', 'Username to connect to database')
29 + .option('-p, --password [password]', 'Password to connect to database')
30 + .option('-s, --schema [schema]', 'Comma separated names of the database schemas. i.e public,extra_schema', list)
31 + .option('-o, --output [output]', 'Output folder')
32 + .option('-c, --config [config]', 'Path of the configuration file')
33 + .option('-t --templateName [templateName]','Use builtin template folder with given name. (default|sequelize4)')
34 + .option(' --nolog', 'No log output')
35 + .option(' --resetConfig', 'Reset configuration. (Side-step. Not for production.)')
36 + .option(' --throwError', 'Instead of logging errors to console, throws error.')
37 +;
38 +
39 +program.on('--help', function(){
40 + console.log(' Connects given PostgreSQL database and generates Sequelize models');
41 + console.log(' automatically. Can be customized via node-config.');
42 + console.log('');
43 + console.log(' Examples:');
44 + console.log('');
45 + console.log(' $ %s -h 127.0.0.1 -d our_crm -u george -p topSeCRet -s public,extra -o ./model', process.argv[0]);
46 + console.log(' $ %s -c ../config/default.json -u natalie -p topSecret', process.argv[0]);
47 + console.log('');
48 +});
49 +
50 +program.parse(process.argv);
51 +
52 +// Show help if no arguments are present.
53 +if (process.argv.length === 2) { program.help(); }
54 +
55 +// Copy all options to options global variable to override config.
56 +['host', 'port', 'database', 'user', 'password', 'schema', 'output', 'config', 'templateName', 'nolog', 'resetConfig', 'throwError'].forEach(
57 + function(option) {
58 + if (program[option] !== undefined) {
59 + options[option] = program[option];
60 + }
61 + }
62 +);
63 +
64 +if (program.templateName === undefined) {
65 + console.warn(
66 + '\n********************************************************************************************\n' +
67 + 'DEPRECIATION WARNING:\n' +
68 + 'You should use either use -t or provide a template folder in your configuration.\n' +
69 + 'Default value for template folder will be not provided to support future Sequelize versions.\n' +
70 + '********************************************************************************************\n'
71 + );
72 +}
73 +
74 +generator(function (err) {
75 + if (err) {
76 + if ( options.throwError ) {
77 + throw(err);
78 + } else {
79 + console.log(err);
80 + }
81 + }
82 + process.exit(0);
83 +}, options);
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 +/**
2 + * @author Özüm Eldoğan
3 + */
4 +/*jslint node: true */
5 +"use strict";
6 +
7 +// PostgreSQL Enum type comes as user-defined. As a result it should be handled manually.
8 +module.exports = {
9 + 'array' : { type: '.ARRAY' },
10 + 'bigint' : { type: '.BIGINT', hasLength: true },
11 + 'bigserial' : { type: '.BIGINT', hasLength: true },
12 + 'bit' : { type: '.CHAR', hasLength: true }, // Not directly supported in Sequelize
13 + 'bit varying' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
14 + 'boolean' : { type: '.BOOLEAN' },
15 + 'box' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
16 + 'bytea' : { type: '.BLOB' },
17 + 'character' : { type: '.CHAR', hasLength: true },
18 + 'character varying' : { type: '.STRING', hasLength: true },
19 + 'cidr' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
20 + 'circle' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
21 + 'date' : { type: '.DATEONLY' },
22 + 'double precision' : { type: '.FLOAT', hasPrecision: true },
23 + 'hstore' : { type: '.HSTORE' },
24 + 'inet' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
25 + 'integer' : { type: '.INTEGER', hasLength: true },
26 + 'interval' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
27 + 'json' : { type: '.JSON' },
28 + 'jsonb' : { type: '.JSONB' },
29 + 'line' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
30 + 'lseg' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
31 + 'macaddr' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
32 + 'money' : { type: '.DECIMAL', hasPrecision: true },
33 + 'numeric' : { type: '.DECIMAL', hasPrecision: true },
34 + 'path' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
35 + 'point' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
36 + 'polygon' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
37 + 'real' : { type: '.FLOAT', hasPrecision: true },
38 + 'smallint' : { type: '.INTEGER', hasLength: true },
39 + 'smallserial' : { type: '.INTEGER', hasLength: true },
40 + 'serial' : { type: '.INTEGER', hasLength: true },
41 + 'text' : { type: '.TEXT' },
42 + 'time without time zone' : { type: '.TIME' },
43 + 'time with time zone' : { type: '.TIME' },
44 + 'timestamp without time zone' : { type: '.DATE' },
45 + 'timestamp with time zone' : { type: '.DATE' },
46 + 'tsquery' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
47 + 'tsvector' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
48 + 'txid_snapshot' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
49 + 'uuid' : { type: '.UUID' },
50 + 'xml' : { type: '.STRING', hasLength: true }, // Not directly supported in Sequelize
51 + 'user-defined' : { type: '.STRING', hasLength: true } // Not directly supported in Sequelize
52 +};
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "sequelize-pg-generator",
3 + "version": "0.9.3",
4 + "description": "Auto Create Sequelize ORM Models from PostgreSQL.",
5 + "main": "index.js",
6 + "bin": {
7 + "spgen": "lib/bin/spgen.js"
8 + },
9 + "scripts": {
10 + "test": "make test"
11 + },
12 + "keywords": [
13 + "postgresql",
14 + "pg",
15 + "postgres",
16 + "database",
17 + "schema",
18 + "model",
19 + "schema",
20 + "export",
21 + "dump",
22 + "etl",
23 + "erd",
24 + "migration",
25 + "transform",
26 + "extract",
27 + "information_schema",
28 + "sequelize",
29 + "orm",
30 + "model",
31 + "structure",
32 + "auto generate",
33 + "meta"
34 + ],
35 + "author": {
36 + "name": "Özüm Eldoğan"
37 + },
38 + "repository": {
39 + "type": "git",
40 + "url": "https://github.com/ozum/sequelize-pg-generator.git"
41 + },
42 + "license": "MIT",
43 + "devDependencies": {
44 + "chai": "^1.10.0",
45 + "ink-docstrap": "^0.4.12",
46 + "mocha": "^2.1.0",
47 + "pg": "^4.1.1",
48 + "pg-hstore": "^2.3.2",
49 + "sequelize": "^3.1.1"
50 + },
51 + "dependencies": {
52 + "async": "^0.9.0",
53 + "commander": "^2.5.1",
54 + "config": "^1.8.1",
55 + "consolidate": "^0.10.0",
56 + "ejs": "^1.0.0",
57 + "fs-extra": "^0.13.0",
58 + "inflection": "^1.5.1",
59 + "js-beautify": "^1.5.4",
60 + "json-stable-stringify": "^1.0.0",
61 + "lodash": "^2.4.1",
62 + "pg-hstore": "^2.3.2",
63 + "pg-structure": "^1.11.3",
64 + "swig": "^1.4.2",
65 + "winston": "^0.8.3"
66 + },
67 + "readmeFilename": "README.md",
68 + "bugs": {
69 + "url": "https://github.com/ozum/sequelize-pg-generator/issues"
70 + },
71 + "homepage": "https://github.com/ozum/sequelize-pg-generator",
72 + "_id": "sequelize-pg-generator@0.1.0",
73 + "_shasum": "4a9deecd8712210defedf25a69548281547363d8",
74 + "_from": "."
75 +}
1 +{% autoescape false %}
2 +
3 +{{ column.accessorName }}: {
4 + type: {{ column.type }}
5 + {{ ifTrue('field', column.name) }}
6 + {{ ifTrue('primaryKey', column.primaryKey) }}
7 + {{ ifTrue('autoIncrement', column.autoIncrement) }}
8 + {{ ifFalse('allowNull', column.allowNull) }}
9 + {{ ifNotUndefined('defaultValue', column.defaultValue) }}
10 + {{ ifTrue('unique', column.unique) }}
11 + {{ ifTrue('comment', column.comment) }}
12 + {{ ifTrue('references', column.references) }}
13 + {{ ifTrue('referencesKey', column.referencesKey) }}
14 + {{ ifTrue('onUpdate', column.onUpdate) }}
15 + {{ ifTrue('onDelete', column.onDelete) }}
16 +}
17 +
18 +{% endautoescape %}
1 +{% autoescape false %}
2 +/*jslint node: true */
3 +"use strict";
4 +
5 +{%- if warning %}
6 +/*------------------------------------------------------------------------------------
7 +
8 +DO NOT EDIT THIS FILE !!! It is generated automatically and will be overwritten.
9 +
10 +To modify this model:
11 +1. Create '{{ table.baseFileName }}.js' file in 'definition-files-custom' directory located in this file's parent directory.
12 +2. Copy the code below and paste it into '{{ table.baseFileName }}.js'.
13 +3. Use utility methods to easily access orm properties.
14 +
15 +"use strict";
16 +var orm = require('{{mainScript}}'),
17 + model = require('./{{ table.baseFileName }}.js'),
18 + util = require('../utils.js')(model),
19 + Seq = orm.Sequelize();
20 +
21 +module.exports = model;
22 +
23 +// Some utility methods:
24 +{% if table.relations|first %}util.getRelation({{ table.relations|first.as }}).onDelete = 'CASCADE'; {% endif %}
25 +{% if table.columns|first %}util.getAttribute({{table.columns|first.accessorName}}).comment = 'This is the comment'; {% endif %}
26 +
27 +------------------------------------------------------------------------------------*/
28 +{%- endif %}
29 +
30 +{% macro ifTrue(label, value) %}
31 + {% if value %}
32 + ,{{ label }}: {{ value }}
33 + {% endif %}
34 +{% endmacro %}
35 +
36 +{% macro ifFalse(label, value) %}
37 + {% if !value && value !== undefined %}
38 + ,{{ label }}: {{ value }}
39 + {% endif %}
40 +{% endmacro %}
41 +
42 +{% macro ifNotUndefined(label, value) %}
43 + {% if value !== undefined %}
44 + ,{{ label }}: {{ value }}
45 + {% endif %}
46 +{% endmacro %}
47 +
48 +{% include "./table.html" %}
49 +
50 +{% endautoescape %}
1 +/**
2 + * This file is auto generated by sequelize-pg-generator.
3 + * @module path/to/model
4 + * @author Özüm Eldoğan
5 + */
6 +
7 +/*jslint node: true, stupid: true, nomen: true */
8 +"use strict";
9 +
10 +var Sequelize = require('sequelize'),
11 + fs = require('fs'),
12 + path = require('path'),
13 + util = require('util'),
14 + models = {},
15 + relationships = {},
16 + modelsPath = '',
17 + definitionDir = 'definition-files',
18 + definitionDirCustom = definitionDir + '-custom',
19 + debug = false,
20 + debugFD = '',
21 + sequelize = null;
22 +
23 +/**
24 + * Requires given npm module file and defines sequelize module according to exported object from that module.
25 + * @private
26 + * @param {string} file - Location of the npm module file which contains model definition.
27 + */
28 +function defineModel(file) {
29 + var object = require(file),
30 + options = object.options || {},
31 + modelName = object.modelName;
32 +
33 + if (debug) {
34 + fs.writeSync(debugFD, 'var ' + modelName + ' = Sequelize.define("' + modelName + '",\n' + util.inspect(object.attributes) + ',\n' + util.inspect(options, {depth: null}) + ');\n\n\n');
35 + }
36 +
37 + models[modelName] = sequelize.define(modelName, object.attributes, options);
38 + if (object.relations !== undefined) {
39 + relationships[modelName] = object.relations;
40 + }
41 +}
42 +
43 +
44 +/**
45 + * Define 'hasMany' and 'belongsTo' relations.
46 + * @private
47 + * @param {string} modelName - Name of the model
48 + * @param {string} relationType - Type of the relation 'hasMany' or 'belongsTo'
49 + * @param {string} targetModelName - Name of the target model which this relation related to.
50 + * @param {Object} options - Sequelize options of relation.
51 + */
52 +function defineRelation(modelName, relationType, targetModelName, options) {
53 + if (debug) {
54 + fs.writeSync(debugFD, modelName + '.' + relationType + '(' + targetModelName + ', ' + util.inspect(options, {depth: null}) + ');\n\n');
55 + }
56 +
57 + models[modelName][relationType](models[targetModelName], options); // account.hasMany(contact, {...})
58 +}
59 +
60 +
61 +/**
62 + * Generates list of definition files by looking given modelsPath directory. It traverses 'definition-files'
63 + * and 'definition-files-custom' directories to generate the list. Files in 'definition-files' will be skipped
64 + * if a file with same name is found in 'definition-files-custom' directory.
65 + * @private
66 + * @returns {Array}
67 + * @example
68 + * var list = getFileList('../model'); // ['./definition-files-custom/public_cart.js', './definition-files/public_account.js]
69 + */
70 +function getFileList() {
71 + var i, file, isOverridden = {}, files = [], customFiles, baseFiles;
72 + baseFiles = fs.readdirSync(path.join(modelsPath, definitionDir));
73 + customFiles = fs.readdirSync(path.join(modelsPath, definitionDirCustom));
74 +
75 + for (i = 0; i < customFiles.length; i = i + 1) {
76 + file = customFiles[i];
77 + if (file.match(/\.js$/)) {
78 + isOverridden[file] = true;
79 + files.push('./' + path.join(definitionDirCustom, file));
80 + }
81 + }
82 +
83 + for (i = 0; i < baseFiles.length; i = i + 1) {
84 + file = baseFiles[i];
85 + if (!isOverridden[file] && file.match(/\.js$/)) {
86 + files.push('./' + path.join(definitionDir, file));
87 + }
88 + }
89 + return files;
90 +}
91 +
92 +
93 +/**
94 + * Iterates all relations and executes given callback on them. Callback is passed
95 + * ({string} modelName, {string} relationType, {string} targetModelName, {Object} relationOptions)
96 + * @private
97 + * @param {function} callback - Callback function.
98 + * @returns {Array}
99 + */
100 +function processAllRelations(callback) {
101 + var i, modelName, relation, relations, result = [];
102 + for (modelName in relationships) {
103 + if (relationships.hasOwnProperty(modelName)) {
104 + relations = relationships[modelName];
105 + for (i = 0; i < relations.length; i = i + 1) {
106 + relation = relations[i];
107 + result.push(callback(modelName, relation.type, relation.model, relation.details));
108 + }
109 + }
110 + }
111 + return result;
112 +}
113 +
114 +
115 +/**
116 + * Initializes models.
117 + * @private
118 + */
119 +function init() {
120 + var debugFile = path.join(__dirname, 'debug.js');
121 +
122 + if (debug) {
123 + if (fs.existsSync(debugFile)) { fs.unlinkSync(debugFile); }
124 + debugFD = fs.openSync(debugFile, 'a');
125 + }
126 +
127 + getFileList(modelsPath).forEach(defineModel);
128 + processAllRelations(defineRelation);
129 +
130 + if (debug) {
131 + fs.closeSync(debugFD);
132 + }
133 +}
134 +
135 +module.exports = {};
136 +
137 +/**
138 + * Sets up sequelize models based on model files in given directory for given database details.
139 + * @param {string} database - Name of the database to connect
140 + * @param {string} username - Username of the database
141 + * @param {string} password - Password of the database
142 + * @param {Object} obj - Object to pass new Sequelize() function. See Sequelize for details.
143 + * @example
144 + * var orm = require('../model');
145 + * orm.setup('path/to/model', 'database', 'user', 'password', {
146 + * host: '127.0.0.1',
147 + * logging: false,
148 + * native: true
149 + * });
150 + */
151 +module.exports.setup = function (database, username, password, obj) {
152 + if (typeof obj !== 'object') { obj = {}; }
153 + if (obj.dialect === undefined || obj.dialect === null) { obj.dialect = 'postgres'; }
154 +
155 + if (arguments.length === 2) {
156 + sequelize = new Sequelize(database, username);
157 + } else if (arguments.length === 3) {
158 + sequelize = new Sequelize(database, username, password);
159 + } else if (arguments.length === 4) {
160 + sequelize = new Sequelize(database, username, password, obj);
161 + }
162 + modelsPath = __dirname;
163 + init();
164 +};
165 +
166 +/**
167 + * Returns requested model with given name.
168 + * @param {string} name - Model name
169 + * @returns {object} - Sequelize model
170 + */
171 +module.exports.model = function (name) {
172 + return models[name];
173 +};
174 +
175 +/**
176 + * Returns Sequelize object.
177 + * @returns {Sequelize} - Sequelize object
178 + */
179 +module.exports.Sequelize = function () {
180 + return Sequelize;
181 +};
182 +
183 +/**
184 + * Returns sequelize instance.
185 + * @returns {Sequelize} - sequelize instance
186 + */
187 +module.exports.sequelize = function () {
188 + return sequelize;
189 +};
1 +{% autoescape false %}
2 +
3 +{
4 + type: {{ relation.type }},
5 + model: {{ relation.model }},
6 + schema: {{ relation.targetSchema }},
7 + table: {{ relation.targetTable }},
8 + source: {{ relation.source }},
9 + details: {
10 + as: {{ relation.as }},
11 + foreignKey: {{ relation.foreignKey }}
12 + {{ ifTrue('otherKey', relation.otherKey) }}
13 + {{ ifTrue('through', relation.through) }}
14 + {{ ifTrue('onDelete', relation.onDelete) }}
15 + {{ ifTrue('onUpdate', relation.onUpdate) }}
16 + }
17 +}
18 +
19 +{% endautoescape %}
1 +{% autoescape false %}
2 +var orm = require('../index.js'),
3 +{{ dataTypeVariable }} = orm.Sequelize();
4 +
5 +module.exports = {
6 + modelName: {{ table.modelName }},
7 + options: {
8 + tableName: {{ table.tableName }}
9 + {{ ifTrue('schema', table.schema) }}
10 + {{ ifTrue('omitNull', table.omitNull) }}
11 + {{ ifFalse('timestamps', table.timestamps) }}
12 + {{ ifTrue('paranoid', table.paranoid) }}
13 + {{ ifTrue('underscored', table.underscored) }}
14 + {{ ifTrue('underscoredAll', table.underscoredAll) }}
15 + {{ ifTrue('freezeTableName', table.freezeTableName) }}
16 + {{ ifTrue('createdAt', table.createdAt) }}
17 + {{ ifTrue('updatedAt', table.updatedAt) }}
18 + {{ ifTrue('deletedAt', table.deletedAt) }}
19 + {{ ifTrue('charset', table.charset) }}
20 + {{ ifTrue('collate', table.collate) }}
21 + {{ ifTrue('comment', table.comment) }}
22 + },
23 + attributes: {
24 + {% for column in table.columns %}
25 + {% include "./column.html" %}{% if not loop.last %},{% endif %}
26 + {% endfor %}
27 + },
28 + relations: [
29 + {% for relation in table.relations %}
30 + {% include "./relation.html" %}{% if not loop.last %},{% endif %}
31 + {% endfor %}
32 + ]
33 +};
34 +
35 +{% endautoescape %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% autoescape false %}
2 +
3 +{{ column.accessorName }}: {
4 + type: {{ column.type }},
5 + allowNull: {{ column.allowNull }},
6 + xlabel: lang.t("{{"fields."+column.accessorName}}")
7 + {{ ifTrue('field', column.name) }}
8 + {{ ifTrue('primaryKey', column.primaryKey) }}
9 + {{ ifTrue('autoIncrement', column.autoIncrement) }}
10 + {{ ifFalse('allowNull', column.allowNull) }}
11 + {{ ifNotUndefined('defaultValue', column.defaultValue) }}
12 + {{ ifTrue('unique', column.unique) }}
13 + {{ ifTrue('comment', column.comment) }}
14 + {{ ifTrue('references', column.references) }}
15 + {{ ifTrue('referencesKey', column.referencesKey) }}
16 + {{ ifTrue('onUpdate', column.onUpdate) }}
17 + {{ ifTrue('onDelete', column.onDelete) }}
18 +}
19 +
20 +{% endautoescape %}
1 +{% autoescape false %}
2 +/*------------------------------------------------------------------------------------
3 +
4 +ARCHIVOS MODELOS GENERADOS AUTOMATICAMENTE, SE RECOMIENDA NO MODIFICAR LOS ARCHIVOS
5 +
6 +Author: Felix Antonio Mamani Quispe
7 +Email: felixddxd@gmail.com
8 +La Paz - Bolivia
9 +
10 +------------------------------------------------------------------------------------*/
11 +"use strict";
12 +
13 +const lang = require("../../lang");
14 +const util = require("../../lib/util");
15 +
16 +{% include "./table.html" %}
17 +
18 +{% endautoescape %}
1 +/**
2 + * This file is auto generated by sequelize-pg-generator.
3 + * @module path/to/model
4 + * @author Özüm Eldoğan
5 + */
6 +
7 +/*jslint node: true, stupid: true, nomen: true */
8 +"use strict";
9 +
10 +var Sequelize = require('sequelize'),
11 + fs = require('fs'),
12 + path = require('path'),
13 + util = require('util'),
14 + models = {},
15 + relationships = {},
16 + modelsPath = '',
17 + definitionDir = 'definition-files',
18 + definitionDirCustom = definitionDir + '-custom',
19 + debug = false,
20 + debugFD = '',
21 + sequelize = null;
22 +
23 +/**
24 + * Requires given npm module file and defines sequelize module according to exported object from that module.
25 + * @private
26 + * @param {string} file - Location of the npm module file which contains model definition.
27 + */
28 +function defineModel(file) {
29 + var object = require(file),
30 + options = object.options || {},
31 + modelName = object.modelName;
32 +
33 + if (debug) {
34 + fs.writeSync(debugFD, 'var ' + modelName + ' = Sequelize.define("' + modelName + '",\n' + util.inspect(object.attributes) + ',\n' + util.inspect(options, {depth: null}) + ');\n\n\n');
35 + }
36 +
37 + models[modelName] = sequelize.define(modelName, object.attributes, options);
38 + if (object.relations !== undefined) {
39 + relationships[modelName] = object.relations;
40 + }
41 +}
42 +
43 +
44 +/**
45 + * Define 'hasMany' and 'belongsTo' relations.
46 + * @private
47 + * @param {string} modelName - Name of the model
48 + * @param {string} relationType - Type of the relation 'hasMany' or 'belongsTo'
49 + * @param {string} targetModelName - Name of the target model which this relation related to.
50 + * @param {Object} options - Sequelize options of relation.
51 + */
52 +function defineRelation(modelName, relationType, targetModelName, options) {
53 + if (debug) {
54 + fs.writeSync(debugFD, modelName + '.' + relationType + '(' + targetModelName + ', ' + util.inspect(options, {depth: null}) + ');\n\n');
55 + }
56 +
57 + models[modelName][relationType](models[targetModelName], options); // account.hasMany(contact, {...})
58 +}
59 +
60 +
61 +/**
62 + * Generates list of definition files by looking given modelsPath directory. It traverses 'definition-files'
63 + * and 'definition-files-custom' directories to generate the list. Files in 'definition-files' will be skipped
64 + * if a file with same name is found in 'definition-files-custom' directory.
65 + * @private
66 + * @returns {Array}
67 + * @example
68 + * var list = getFileList('../model'); // ['./definition-files-custom/public_cart.js', './definition-files/public_account.js]
69 + */
70 +function getFileList() {
71 + var i, file, isOverridden = {}, files = [], customFiles, baseFiles;
72 + baseFiles = fs.readdirSync(path.join(modelsPath, definitionDir));
73 + customFiles = fs.readdirSync(path.join(modelsPath, definitionDirCustom));
74 +
75 + for (i = 0; i < customFiles.length; i = i + 1) {
76 + file = customFiles[i];
77 + if (file.match(/\.js$/)) {
78 + isOverridden[file] = true;
79 + files.push('./' + path.join(definitionDirCustom, file));
80 + }
81 + }
82 +
83 + for (i = 0; i < baseFiles.length; i = i + 1) {
84 + file = baseFiles[i];
85 + if (!isOverridden[file] && file.match(/\.js$/)) {
86 + files.push('./' + path.join(definitionDir, file));
87 + }
88 + }
89 + return files;
90 +}
91 +
92 +
93 +/**
94 + * Iterates all relations and executes given callback on them. Callback is passed
95 + * ({string} modelName, {string} relationType, {string} targetModelName, {Object} relationOptions)
96 + * @private
97 + * @param {function} callback - Callback function.
98 + * @returns {Array}
99 + */
100 +function processAllRelations(callback) {
101 + var i, modelName, relation, relations, result = [];
102 + for (modelName in relationships) {
103 + if (relationships.hasOwnProperty(modelName)) {
104 + relations = relationships[modelName];
105 + for (i = 0; i < relations.length; i = i + 1) {
106 + relation = relations[i];
107 + result.push(callback(modelName, relation.type, relation.model, relation.details));
108 + }
109 + }
110 + }
111 + return result;
112 +}
113 +
114 +
115 +/**
116 + * Initializes models.
117 + * @private
118 + */
119 +function init() {
120 + var debugFile = path.join(__dirname, 'debug.js');
121 +
122 + if (debug) {
123 + if (fs.existsSync(debugFile)) { fs.unlinkSync(debugFile); }
124 + debugFD = fs.openSync(debugFile, 'a');
125 + }
126 +
127 + getFileList(modelsPath).forEach(defineModel);
128 + processAllRelations(defineRelation);
129 +
130 + if (debug) {
131 + fs.closeSync(debugFD);
132 + }
133 +}
134 +
135 +module.exports = {};
136 +
137 +/**
138 + * Sets up sequelize models based on model files in given directory for given database details.
139 + * @param {string} database - Name of the database to connect
140 + * @param {string} username - Username of the database
141 + * @param {string} password - Password of the database
142 + * @param {Object} obj - Object to pass new Sequelize() function. See Sequelize for details.
143 + * @example
144 + * var orm = require('../model');
145 + * orm.setup('path/to/model', 'database', 'user', 'password', {
146 + * host: '127.0.0.1',
147 + * logging: false,
148 + * native: true
149 + * });
150 + */
151 +module.exports.setup = function (database, username, password, obj) {
152 + if (typeof obj !== 'object') { obj = {}; }
153 + if (obj.dialect === undefined || obj.dialect === null) { obj.dialect = 'postgres'; }
154 +
155 + if (arguments.length === 2) {
156 + sequelize = new Sequelize(database, username);
157 + } else if (arguments.length === 3) {
158 + sequelize = new Sequelize(database, username, password);
159 + } else if (arguments.length === 4) {
160 + sequelize = new Sequelize(database, username, password, obj);
161 + }
162 + modelsPath = __dirname;
163 + init();
164 +};
165 +
166 +/**
167 + * Returns requested model with given name.
168 + * @param {string} name - Model name
169 + * @returns {object} - Sequelize model
170 + */
171 +module.exports.model = function (name) {
172 + return models[name];
173 +};
174 +
175 +/**
176 + * Returns Sequelize object.
177 + * @returns {Sequelize} - Sequelize object
178 + */
179 +module.exports.Sequelize = function () {
180 + return Sequelize;
181 +};
182 +
183 +/**
184 + * Returns sequelize instance.
185 + * @returns {Sequelize} - sequelize instance
186 + */
187 +module.exports.sequelize = function () {
188 + return sequelize;
189 +};
1 +{% autoescape false %}
2 +
3 +{
4 + type: {{ relation.type }},
5 + model: {{ relation.model }},
6 + schema: {{ relation.targetSchema }},
7 + table: {{ relation.targetTable }},
8 + source: {{ relation.source }},
9 + details: {
10 + as: {{ relation.as }},
11 + foreignKey: {{ relation.foreignKey }}
12 + {{ ifTrue('otherKey', relation.otherKey) }}
13 + {{ ifTrue('through', relation.through) }}
14 + {{ ifTrue('onDelete', relation.onDelete) }}
15 + {{ ifTrue('onUpdate', relation.onUpdate) }}
16 + }
17 +}
18 +
19 +{% endautoescape %}
1 +{% autoescape false %}
2 +
3 +module.exports = (sequelize, DataTypes) => {
4 + let fields = {
5 + {% for column in table.columns %}
6 + {% include "./column.html" %}{% if not loop.last %},{% endif %}
7 + {% endfor %}
8 + }
9 + fields = util.setTimestamps(fields);
10 +
11 + let {{table.modelName}}= sequelize.define("{{ table.tableName }}", fields, {
12 + timestamps: false,
13 + tableName: "{{ table.tableName }}",
14 + schema: "{{ table.schema }}",
15 + });
16 +
17 + return {{table.modelName}};
18 +};
19 +
20 +{% endautoescape %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% autoescape false %}
2 +
3 +{{ column.accessorName }}: {
4 + type: {{ column.type }}
5 + {{ ifTrue('field', column.name) }}
6 + {{ ifTrue('primaryKey', column.primaryKey) }}
7 + {{ ifTrue('autoIncrement', column.autoIncrement) }}
8 + {{ ifFalse('allowNull', column.allowNull) }}
9 + {{ ifNotUndefined('defaultValue', column.defaultValue) }}
10 + {{ ifTrue('unique', column.unique) }}
11 + {{ ifTrue('comment', column.comment) }}
12 +{% if column.references && column.referencesKey %}
13 + ,references: { model: {{column.references}}, key: {{column.referencesKey}} }
14 +{% endif %}
15 + {{ ifTrue('onUpdate', column.onUpdate) }}
16 + {{ ifTrue('onDelete', column.onDelete) }}
17 +}
18 +
19 +{% endautoescape %}
1 +{% autoescape false %}
2 +/*jslint node: true */
3 +"use strict";
4 +
5 +{%- if warning %}
6 +/*------------------------------------------------------------------------------------
7 +
8 +DO NOT EDIT THIS FILE !!! It is generated automatically and will be overwritten.
9 +
10 +To modify this model:
11 +1. Create '{{ table.baseFileName }}.js' file in 'definition-files-custom' directory located in this file's parent directory.
12 +2. Copy the code below and paste it into '{{ table.baseFileName }}.js'.
13 +3. Use utility methods to easily access orm properties.
14 +
15 +"use strict";
16 +var orm = require('{{mainScript}}'),
17 + model = require('./{{ table.baseFileName }}.js'),
18 + util = require('../utils.js')(model),
19 + Seq = orm.Sequelize();
20 +
21 +module.exports = model;
22 +
23 +// Some utility methods:
24 +{% if table.relations|first %}util.getRelation({{ table.relations|first.as }}).onDelete = 'CASCADE'; {% endif %}
25 +{% if table.columns|first %}util.getAttribute({{table.columns|first.accessorName}}).comment = 'This is the comment'; {% endif %}
26 +
27 +------------------------------------------------------------------------------------*/
28 +{%- endif %}
29 +
30 +{% macro ifTrue(label, value) %}
31 + {% if value %}
32 + ,{{ label }}: {{ value }}
33 + {% endif %}
34 +{% endmacro %}
35 +
36 +{% macro ifFalse(label, value) %}
37 + {% if !value && value !== undefined %}
38 + ,{{ label }}: {{ value }}
39 + {% endif %}
40 +{% endmacro %}
41 +
42 +{% macro ifNotUndefined(label, value) %}
43 + {% if value !== undefined %}
44 + ,{{ label }}: {{ value }}
45 + {% endif %}
46 +{% endmacro %}
47 +
48 +{% include "./table.html" %}
49 +
50 +{% endautoescape %}
1 +/**
2 + * This file is auto generated by sequelize-pg-generator.
3 + * @module path/to/model
4 + * @author Özüm Eldoğan
5 + */
6 +
7 +/*jslint node: true, stupid: true, nomen: true */
8 +"use strict";
9 +
10 +var Sequelize = require('sequelize'),
11 + fs = require('fs'),
12 + path = require('path'),
13 + util = require('util'),
14 + models = {},
15 + relationships = {},
16 + modelsPath = '',
17 + definitionDir = 'definition-files',
18 + definitionDirCustom = definitionDir + '-custom',
19 + debug = false,
20 + debugFD = '',
21 + sequelize = null;
22 +
23 +/**
24 + * Requires given npm module file and defines sequelize module according to exported object from that module.
25 + * @private
26 + * @param {string} file - Location of the npm module file which contains model definition.
27 + */
28 +function defineModel(file) {
29 + var object = require(file),
30 + options = object.options || {},
31 + modelName = object.modelName;
32 +
33 + if (debug) {
34 + fs.writeSync(debugFD, 'var ' + modelName + ' = Sequelize.define("' + modelName + '",\n' + util.inspect(object.attributes) + ',\n' + util.inspect(options, {depth: null}) + ');\n\n\n');
35 + }
36 +
37 + models[modelName] = sequelize.define(modelName, object.attributes, options);
38 + if (object.relations !== undefined) {
39 + relationships[modelName] = object.relations;
40 + }
41 +}
42 +
43 +
44 +/**
45 + * Define 'hasMany' and 'belongsTo' relations.
46 + * @private
47 + * @param {string} modelName - Name of the model
48 + * @param {string} relationType - Type of the relation 'hasMany' or 'belongsTo'
49 + * @param {string} targetModelName - Name of the target model which this relation related to.
50 + * @param {Object} options - Sequelize options of relation.
51 + */
52 +function defineRelation(modelName, relationType, targetModelName, options) {
53 + if (debug) {
54 + fs.writeSync(debugFD, modelName + '.' + relationType + '(' + targetModelName + ', ' + util.inspect(options, {depth: null}) + ');\n\n');
55 + }
56 +
57 + models[modelName][relationType](models[targetModelName], options); // account.hasMany(contact, {...})
58 +}
59 +
60 +
61 +/**
62 + * Generates list of definition files by looking given modelsPath directory. It traverses 'definition-files'
63 + * and 'definition-files-custom' directories to generate the list. Files in 'definition-files' will be skipped
64 + * if a file with same name is found in 'definition-files-custom' directory.
65 + * @private
66 + * @returns {Array}
67 + * @example
68 + * var list = getFileList('../model'); // ['./definition-files-custom/public_cart.js', './definition-files/public_account.js]
69 + */
70 +function getFileList() {
71 + var i, file, isOverridden = {}, files = [], customFiles, baseFiles;
72 + baseFiles = fs.readdirSync(path.join(modelsPath, definitionDir));
73 + customFiles = fs.readdirSync(path.join(modelsPath, definitionDirCustom));
74 +
75 + for (i = 0; i < customFiles.length; i = i + 1) {
76 + file = customFiles[i];
77 + if (file.match(/\.js$/)) {
78 + isOverridden[file] = true;
79 + files.push('./' + path.join(definitionDirCustom, file));
80 + }
81 + }
82 +
83 + for (i = 0; i < baseFiles.length; i = i + 1) {
84 + file = baseFiles[i];
85 + if (!isOverridden[file] && file.match(/\.js$/)) {
86 + files.push('./' + path.join(definitionDir, file));
87 + }
88 + }
89 + return files;
90 +}
91 +
92 +
93 +/**
94 + * Iterates all relations and executes given callback on them. Callback is passed
95 + * ({string} modelName, {string} relationType, {string} targetModelName, {Object} relationOptions)
96 + * @private
97 + * @param {function} callback - Callback function.
98 + * @returns {Array}
99 + */
100 +function processAllRelations(callback) {
101 + var i, modelName, relation, relations, result = [];
102 + for (modelName in relationships) {
103 + if (relationships.hasOwnProperty(modelName)) {
104 + relations = relationships[modelName];
105 + for (i = 0; i < relations.length; i = i + 1) {
106 + relation = relations[i];
107 + result.push(callback(modelName, relation.type, relation.model, relation.details));
108 + }
109 + }
110 + }
111 + return result;
112 +}
113 +
114 +
115 +/**
116 + * Initializes models.
117 + * @private
118 + */
119 +function init() {
120 + var debugFile = path.join(__dirname, 'debug.js');
121 +
122 + if (debug) {
123 + if (fs.existsSync(debugFile)) { fs.unlinkSync(debugFile); }
124 + debugFD = fs.openSync(debugFile, 'a');
125 + }
126 +
127 + getFileList(modelsPath).forEach(defineModel);
128 + processAllRelations(defineRelation);
129 +
130 + if (debug) {
131 + fs.closeSync(debugFD);
132 + }
133 +}
134 +
135 +module.exports = {};
136 +
137 +/**
138 + * Sets up sequelize models based on model files in given directory for given database details.
139 + * @param {string} database - Name of the database to connect
140 + * @param {string} username - Username of the database
141 + * @param {string} password - Password of the database
142 + * @param {Object} obj - Object to pass new Sequelize() function. See Sequelize for details.
143 + * @example
144 + * var orm = require('../model');
145 + * orm.setup('path/to/model', 'database', 'user', 'password', {
146 + * host: '127.0.0.1',
147 + * logging: false,
148 + * native: true
149 + * });
150 + */
151 +module.exports.setup = function (database, username, password, obj) {
152 + if (typeof obj !== 'object') { obj = {}; }
153 + if (obj.dialect === undefined || obj.dialect === null) { obj.dialect = 'postgres'; }
154 +
155 + if (arguments.length === 2) {
156 + sequelize = new Sequelize(database, username);
157 + } else if (arguments.length === 3) {
158 + sequelize = new Sequelize(database, username, password);
159 + } else if (arguments.length === 4) {
160 + sequelize = new Sequelize(database, username, password, obj);
161 + }
162 + modelsPath = __dirname;
163 + init();
164 +};
165 +
166 +/**
167 + * Returns requested model with given name.
168 + * @param {string} name - Model name
169 + * @returns {object} - Sequelize model
170 + */
171 +module.exports.model = function (name) {
172 + return models[name];
173 +};
174 +
175 +/**
176 + * Returns Sequelize object.
177 + * @returns {Sequelize} - Sequelize object
178 + */
179 +module.exports.Sequelize = function () {
180 + return Sequelize;
181 +};
182 +
183 +/**
184 + * Returns sequelize instance.
185 + * @returns {Sequelize} - sequelize instance
186 + */
187 +module.exports.sequelize = function () {
188 + return sequelize;
189 +};
1 +{% autoescape false %}
2 +
3 +{
4 + type: {{ relation.type }},
5 + model: {{ relation.model }},
6 + schema: {{ relation.targetSchema }},
7 + table: {{ relation.targetTable }},
8 + source: {{ relation.source }},
9 + details: {
10 + as: {{ relation.as }},
11 + foreignKey: {{ relation.foreignKey }}
12 + {{ ifTrue('otherKey', relation.otherKey) }}
13 + {{ ifTrue('through', relation.through) }}
14 + {{ ifTrue('onDelete', relation.onDelete) }}
15 + {{ ifTrue('onUpdate', relation.onUpdate) }}
16 + }
17 +}
18 +
19 +{% endautoescape %}
1 +{% autoescape false %}
2 +var orm = require('../index.js'),
3 +{{ dataTypeVariable }} = orm.Sequelize();
4 +
5 +module.exports = {
6 + modelName: {{ table.modelName }},
7 + options: {
8 + tableName: {{ table.tableName }}
9 + {{ ifTrue('schema', table.schema) }}
10 + {{ ifTrue('omitNull', table.omitNull) }}
11 + {{ ifFalse('timestamps', table.timestamps) }}
12 + {{ ifTrue('paranoid', table.paranoid) }}
13 + {{ ifTrue('underscored', table.underscored) }}
14 + {{ ifTrue('underscoredAll', table.underscoredAll) }}
15 + {{ ifTrue('freezeTableName', table.freezeTableName) }}
16 + {{ ifTrue('createdAt', table.createdAt) }}
17 + {{ ifTrue('updatedAt', table.updatedAt) }}
18 + {{ ifTrue('deletedAt', table.deletedAt) }}
19 + {{ ifTrue('charset', table.charset) }}
20 + {{ ifTrue('collate', table.collate) }}
21 + {{ ifTrue('comment', table.comment) }}
22 + },
23 + attributes: {
24 + {% for column in table.columns %}
25 + {% include "./column.html" %}{% if not loop.last %},{% endif %}
26 + {% endfor %}
27 + },
28 + relations: [
29 + {% for relation in table.relations %}
30 + {% include "./relation.html" %}{% if not loop.last %},{% endif %}
31 + {% endfor %}
32 + ]
33 +};
34 +
35 +{% endautoescape %}
...\ No newline at end of file ...\ No newline at end of file
1 +/**
2 + * Utility methods to modify and customize auto generated models without affecting further auto generations.
3 + * Require this module from model customization scripts located in path/to/model/definitions-files-custom directory.
4 + * @class
5 + * @author Özüm Eldoğan
6 + */
7 +
8 +
9 +/*jslint node: true */
10 +"use strict";
11 +
12 +
13 +/**
14 + * @constructor
15 + * @param model
16 + */
17 +var GeneratorUtil = function (model) {
18 + this.model = model;
19 +};
20 +
21 +
22 +/**
23 + * Searches and returns relation with the given alias. Alias is defined in sequelize options with parameter 'as'
24 + * @method
25 + * @param {string} as - Alias of the relation.
26 + * @returns {Object}
27 + */
28 +GeneratorUtil.prototype.getRelation = function (as) {
29 + var i,
30 + relations = this.model.relations;
31 + for (i = 0; i < relations.length; i = i + 1) {
32 + if (relations[i].details.as === as) {
33 + return relations[i];
34 + }
35 + }
36 +};
37 +
38 +
39 +/**
40 + * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
41 + * @method
42 + * @param {string} name - Name of the attribute.
43 + * @returns {Object}
44 + */
45 +GeneratorUtil.prototype.getAttribute = function (name) {
46 + return this.model.attributes[name];
47 +};
48 +
49 +
50 +/**
51 + * Searches and returns attribute with the given alias. Alias is defined in sequelize options with parameter 'as'
52 + * @method
53 + * @param {string} oldName - Name of the attribute which it's name to be changed.
54 + * @param {string} newName - New name of the attribute.
55 + * @throws Will throw error if there is already an attribute with new name exists or attribute with oldName does not exists.
56 + */
57 +GeneratorUtil.prototype.renameAttribute = function (oldName, newName) {
58 + if (this.model.attributes[newName] !== undefined) {
59 + throw new Error('There is already an attribute with the same name ("' + newName + '") in table "' + this.model.modelName + '".');
60 + }
61 + if (this.model.attributes[oldName] === undefined) {
62 + throw new Error('There is no attribute with the name "' + oldName + '". in table "' + this.model.modelName + '".');
63 + }
64 + this.model.attributes[newName] = this.model.attributes[oldName];
65 + delete this.model.attributes[oldName];
66 +};
67 +
68 +
69 +/**
70 + * Creates and returns new object with utility functions.
71 + * @param model
72 + * @returns {GeneratorUtil}
73 + */
74 +module.exports = function (model) {
75 + return new GeneratorUtil(model);
76 +};
77 +
1 +/*jslint node: true, stupid: true, nomen:true */
2 +/*global describe, it, before, beforeEach, after, afterEach */
3 +"use strict";
4 +
5 +var assert = require('chai').assert;
6 +var testDB = require('./util/db.js');
7 +var path = require('path');
8 +var fs = require('fs-extra');
9 +var cart, account;
10 +
11 +
12 +before(function (done) {
13 + testDB.generate(1, { resetConfig: true, nolog: true, config: path.join(__dirname, 'util', 'config', 'reverse-config.json'), output: path.join(__dirname, 'model-different') }, done);
14 +});
15 +
16 +before(function(done) {
17 + cart = require('./model-different/definition-files/cart.js');
18 + account = require('./model-different/definition-files/account.js');
19 + done();
20 +});
21 +after(function (done) {
22 + fs.removeSync(path.join(__dirname, 'model-different'));
23 + testDB.dropDB(done);
24 +});
25 +
26 +describe('cart', function () {
27 + it('should have model file.', function () {
28 + assert.isTrue(fs.existsSync(path.join(__dirname, 'model-different', 'definition-files', 'cart.js')));
29 + });
30 + it('should have model name.', function () {
31 + assert.equal(cart.modelName, 'cart');
32 + });
33 + it('should have createdAt attribute.', function () {
34 + assert.equal(cart.attributes.created_at.field, 'created_at');
35 + });
36 + it('should have relations.', function () {
37 + assert.equal(cart.relations.length, 3);
38 + });
39 +});
40 +
41 +describe('account', function () {
42 + it('should not have relation to other_schema.', function () {
43 + var found = false;
44 + account.relations.forEach(function (relation) {
45 + if (relation.model === 'otherSchema.otherSchemaTable') {
46 + found = true;
47 + }
48 + assert.isFalse(found);
49 + });
50 + });
51 + it('should have true as default value for is_active', function() {
52 + assert.equal(account.attributes.is_active.defaultValue, true);
53 + });
54 + it('should have false as default value for def_false', function() {
55 + assert.equal(account.attributes.def_false.defaultValue, false);
56 + });
57 +});
1 +/*jslint node: true, stupid: true, nomen:true */
2 +/*global describe, it, before, beforeEach, after, afterEach */
3 +"use strict";
4 +
5 +var assert = require('chai').assert;
6 +var testDB = require('./util/db.js');
7 +var path = require('path');
8 +var fs = require('fs-extra');
9 +var cart, account;
10 +
11 +
12 +before(function (done) {
13 + testDB.generate(1, { resetConfig: true, nolog: true, config: path.join(__dirname, 'util', 'config', 'template-sequelize4.json'), output: path.join(__dirname, 'model-sequelize4') }, done);
14 +});
15 +
16 +before(function(done) {
17 + cart = require('./model-sequelize4/definition-files/public_cart.js');
18 + account = require('./model-sequelize4/definition-files/public_account.js');
19 + done();
20 +});
21 +after(function (done) {
22 + fs.removeSync(path.join(__dirname, 'model-sequelize4'));
23 + testDB.dropDB(done);
24 +});
25 +
26 +describe('cart', function () {
27 + it('should have model file.', function () {
28 + assert.isTrue(fs.existsSync(path.join(__dirname, 'model-sequelize4', 'definition-files', 'public_cart.js')));
29 + });
30 + it('should have references object.', function () {
31 + assert.deepEqual(cart.attributes.contactId.references, {
32 + model: "public.contact",
33 + key: "contact_id"
34 + });
35 + });
36 +});
1 +/*jslint node: true, stupid: true, nomen:true */
2 +/*global describe, it, before, beforeEach, after, afterEach */
3 +"use strict";
4 +
5 +var assert = require('chai').assert;
6 +var testDB = require('./util/db.js');
7 +var path = require('path');
8 +var fs = require('fs-extra');
9 +var cart, account;
10 +
11 +before(function (done) {
12 + testDB.generate(1, { resetConfig: true, nolog: true, output: path.join(__dirname, 'model') }, done);
13 +});
14 +
15 +before(function(done) {
16 + cart = require('./model/definition-files/public_cart.js');
17 + account = require('./model/definition-files/public_account.js');
18 + done();
19 +});
20 +
21 +after(function (done) {
22 + fs.removeSync(path.join(__dirname, 'model'));
23 + testDB.dropDB(done);
24 +});
25 +
26 +describe('public.cart', function () {
27 +
28 + it('should have model file.', function () {
29 + assert.isTrue(fs.existsSync(path.join(__dirname, 'model', 'definition-files', 'public_cart.js')));
30 + });
31 + it('should have model name.', function () {
32 + assert.equal(cart.modelName, 'public.cart');
33 + });
34 + it('should have createdAt attribute.', function () {
35 + assert.equal(cart.attributes.createdAt.field, 'created_at');
36 + });
37 + it('should have relations.', function () {
38 + assert.equal(cart.relations.length, 3);
39 + });
40 +});
41 +
42 +describe('public.account', function () {
43 + it('should have relation to other_schema.', function () {
44 + var found = false;
45 + account.relations.forEach(function (relation) {
46 + if (relation.model === 'otherSchema.otherSchemaTable') {
47 + found = true;
48 + }
49 + assert.isTrue(found);
50 + });
51 + });
52 +});
...\ No newline at end of file ...\ No newline at end of file
1 +/*jslint node: true, stupid: true, nomen:true */
2 +/*global describe, it, before, beforeEach, after, afterEach */
3 +"use strict";
4 +
5 +var assert = require('chai').assert;
6 +var testDB = require('./util/db.js');
7 +var path = require('path');
8 +var fs = require('fs-extra');
9 +var account, contact;
10 +
11 +
12 +
13 +before(function (done) {
14 + testDB.generate(1, { resetConfig: true, nolog: true, output: path.join(__dirname, 'model') }, done);
15 +});
16 +
17 +before(function(done) {
18 + var orm = require('./model');
19 + orm.setup(testDB.dbConfig.database, testDB.dbConfig.user, testDB.dbConfig.password, { host: testDB.dbConfig.host, logging: false});
20 + var sequelize = orm.sequelize;
21 + account = orm.model('public.account'); // Can be configured without schema.
22 + contact = orm.model('public.contact'); // Can be configured without schema.
23 + done();
24 +});
25 +
26 +after(function (done) {
27 + fs.removeSync(path.join(__dirname, 'model'));
28 + testDB.dropDB(done);
29 +});
30 +
31 +describe('public.account', function () {
32 +
33 + // Test one-to-many
34 + it('should have many primary contacts.', function (done) {
35 + account.findAll({ include: [ { model: contact, as: "primaryContacts" } ] }).then(function(data) {
36 + assert.equal(data[0].primaryContacts[0].name, "Özüm");
37 + done();
38 + });
39 + });
40 +});
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "sequelize-pg-generator": {
3 + "database": {
4 + "schema": ["public"]
5 + },
6 + "generate": {
7 + "stripFirstTableFromHasMany": false,
8 + "addTableNameToManyToMany": false,
9 + "hasManyThrough": false,
10 + "belongsToMany": true,
11 + "prefixForBelongsTo": "custom",
12 + "useSchemaName": false,
13 + "modelCamelCase": false,
14 + "relationAccessorCamelCase": false,
15 + "columnAccessorCamelCase": false,
16 + "columnDefault": true,
17 + "columnDescription": false,
18 + "columnAutoIncrement": false,
19 + "tableDescription": false,
20 + "dataTypeVariable": "Sequelize",
21 + "skipTable": ["type_table"]
22 + }
23 + }
24 +}
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "sequelize-pg-generator": {
3 + "template": {
4 + "folder": "template/sequelize4"
5 + }
6 + }
7 +}
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +/*jslint node: true, nomen: true, stupid: true */
2 +"use strict";
3 +
4 +var fs = require('fs');
5 +var path = require('path');
6 +var pg = require('pg');
7 +var async = require('async');
8 +var lodash = require('lodash');
9 +var dbConfig = { host: 'localhost', port: 5432, user: 'user', password: 'password', database: 'pg_generator_test_625393' };
10 +var generator = require('../../lib/index.js');
11 +
12 +var conString = 'postgres://' + dbConfig.user + ':' + dbConfig.password + '@' + dbConfig.host + ':' + dbConfig.port + '/'; //'postgres://user:pass@host:port/'
13 +var conStringTest = conString + dbConfig.database; //'postgres://user:pass@host:port/db'
14 +var conStringTemplate = conString + 'template1'; //'postgres://user:pass@host:port/db'
15 +
16 +var sql = {
17 + createDB : "CREATE DATABASE pg_generator_test_625393 WITH ENCODING = 'UTF8' TEMPLATE = template0;",
18 + dropDB : "DROP DATABASE IF EXISTS pg_generator_test_625393;",
19 + createSchema : function (sqlID) { return fs.readFileSync(path.join(__dirname, 'create-test-db-' + sqlID + '.sql')).toString(); },
20 + dropConnection : "SELECT pg_terminate_backend(pid) FROM pg_stat_activity where datname='pg_generator_test_625393';"
21 +};
22 +
23 +pg.on('error', function (err) {
24 + // Do nothing on termination due to admin command. We do this to drop previously created test db.
25 + if (!err.message.match('terminating connection due to administrator command')) { console.log('Database error!', err); }
26 +});
27 +
28 +module.exports.dbConfig = dbConfig;
29 +
30 +module.exports.generate = function generate(sqlId, options, callback) {
31 + module.exports.resetDB(sqlId, function () {
32 + generator(function (err) {
33 + if (err) { callback(err); return; }
34 + callback();
35 + }, lodash.defaults(options, {
36 + database: 'pg_generator_test_625393',
37 + user: dbConfig.user,
38 + password: dbConfig.password,
39 + output: path.join(__dirname, '..', 'model'),
40 + schema: ['public', 'other_schema'],
41 + nolog: true
42 + }));
43 + });
44 +};
45 +
46 +module.exports.resetDB = function resetDB(sqlID, callback) {
47 + if (sqlID === undefined) { sqlID = 1; }
48 + var client = new pg.Client(conStringTemplate);
49 +
50 + client.connect(function () {
51 + async.series([
52 + client.query.bind(client, sql.dropConnection),
53 + client.query.bind(client, sql.dropDB),
54 + client.query.bind(client, sql.createDB),
55 + function (next) {
56 + var clientTest = new pg.Client(conStringTest);
57 + clientTest.connect(function () {
58 + clientTest.query(sql.createSchema(sqlID), function () {
59 + clientTest.end();
60 + next();
61 + });
62 + });
63 + }
64 + ], function (err) {
65 + if (err) { throw err; }
66 + client.end();
67 + callback();
68 + });
69 + });
70 +};
71 +
72 +module.exports.dropDB = function dropDB(callback) {
73 + var client = new pg.Client(conStringTemplate);
74 +
75 + client.connect(function () {
76 + async.series([
77 + client.query.bind(client, sql.dropConnection),
78 + client.query.bind(client, sql.dropDB)
79 + ], function (err) {
80 + if (err) { throw err; }
81 + client.end();
82 + callback();
83 + });
84 + });
85 +};
86 +
87 +module.exports.dbConfig = dbConfig;
...\ No newline at end of file ...\ No newline at end of file