├── public
├── styles
│ └── styles.css
├── dragon.jpg
├── app
│ └── app.js
├── templates
│ └── create.html
└── Controllers
│ └── Controller.js
├── .bowerrc
├── .idea
├── misc.xml
├── scopes
│ └── scope_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── solo.iml
└── dbnavigator.xml
├── README.md
├── bower.json
├── .gitignore
├── index.html
└── _PRESS-RELEASE.md
/public/styles/styles.css:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/public/dragon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pdiniz13/SQL-Helper/HEAD/public/dragon.jpg
--------------------------------------------------------------------------------
/.bowerrc:
--------------------------------------------------------------------------------
1 | {
2 | "directory": "public/components/",
3 | "analytics": false,
4 | "timeout": 120000
5 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/scopes/scope_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SQL-Helper
2 | This application is meant to help developers better visualy Table Relationships in a database.
3 | It also generates SQL statemetns which create that database.
4 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/solo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/public/app/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ppp on 3/9/2015.
3 | */
4 | angular.module('sql', [
5 | 'sql.controller',
6 | 'ui.router'
7 | ])
8 | .config(function($stateProvider, $urlRouterProvider) {
9 | $urlRouterProvider.otherwise("/create");
10 | $stateProvider
11 | .state('create', {
12 | templateUrl: './public/templates/create.html',
13 | controller: 'SqlController',
14 | url: '/create'
15 | })
16 | });
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Database Analyzer",
3 | "version": "0.0.0",
4 | "authors": [],
5 | "license": "MIT",
6 | "ignore": [
7 | "**/.*",
8 | "node_modules",
9 | "bower_components"
10 | ],
11 | "dependencies": {
12 | "angular": "~1.3.14",
13 | "angular-route": "~1.2.18",
14 | "angular-mocks": "~1.2.18",
15 | "bootstrap": "~3.3.2",
16 | "angular-ui-router": "~0.2.13",
17 | "ngFx": "~1.0.6"
18 | },
19 | "resolutions": {
20 | "angular": "1.3.14"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### node etc ###
2 |
3 | # Logs
4 | logs
5 | *.log
6 |
7 | # Runtime data
8 | pids
9 | *.pid
10 | *.seed
11 |
12 | # Directory for instrumented libs generated by jscoverage/JSCover
13 | lib-cov
14 |
15 | # Coverage directory used by tools like istanbul
16 | coverage
17 |
18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19 | .grunt
20 |
21 | # Compiled Dirs (http://nodejs.org/api/addons.html)
22 | build/
23 | dist/
24 |
25 | # Dependency directorys
26 | # Deployed apps should consider commenting these lines out:
27 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
28 | node_modules/
29 | public/bower_components/
30 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Sql Helpers
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | Sql Helpers
14 |
15 |
16 | This application assumes that you have your data in it's first normalized form.
17 | If you dont know how to do this please read the following article:
18 | First Normal Form You do not need to add a
19 | primary key the application will do that for you.
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/public/templates/create.html:
--------------------------------------------------------------------------------
1 |
2 |
Data Input
3 |
4 |
48 |
49 |
Generate MySql
50 |
51 |
52 |
53 |
54 |
55 | {{table.name}}
56 |
57 | {{newColumn.name}}
58 |
59 |
60 |
61 |
62 |
63 |
{{sqlString}}
64 |
--------------------------------------------------------------------------------
/_PRESS-RELEASE.md:
--------------------------------------------------------------------------------
1 | # Project Name #
2 |
3 |
18 |
19 | ## Heading ##
20 | > Database Normalization
21 |
22 | ## Sub-Heading ##
23 | > This is an application that shows you how to normalize your SQL Tables
24 |
25 | ## Summary ##
26 | > You provide the application with your current tables columns and dependencies the application will tell you how to
27 | better normalize the table. The application will provide you with information as to where foreign keys should go
28 | and when helper tables should be created.
29 |
30 | ## Problem ##
31 | > Less and less frontend developers today are properly introduced to SQL which leaves them without a clear
32 | understanding on how to properly structure their data before sending it to a database. This application simplifies
33 | the process of database normalization and tries to demonstrate to the developer what his data will look like when
34 | normalized.
35 |
36 | ## Solution ##
37 | > This application simplifies the process of database normalization and tries to demonstrate to the developer what his
38 | data will look like when normalized.
39 |
40 | ## Quote from You ##
41 | > A quote from a spokesperson in your company.
42 |
43 | ## How to Get Started ##
44 | > In order to get started all you need to do is open up the application and provide it with the current information
45 | on your data.
46 |
47 | ## Customer Quote ##
48 | >
49 |
50 | ## Closing and Call to Action ##
51 | > This application is meant to help clarify database structures and normalization if you are interested in working with
52 | databases I would recommend reading the Murach's SQL Server 2012 for Developers and Murach's MySQL (2nd Edition)
--------------------------------------------------------------------------------
/public/Controllers/Controller.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Created by ppp on 3/9/2015.
3 | */
4 |
5 | angular.module('sql.controller', [])
6 |
7 | .controller('SqlController', ['$scope', 'Tables', function($scope, Tables) {
8 | $scope.name = '';
9 | $scope.columns = [{id: 'col1'}];
10 | $scope.tables = Tables.tables;
11 | $scope.contains = null;
12 | $scope.depends = null;
13 | $scope.sqlString = '';
14 | $scope.addNewCol = function() {
15 | var newItemNo = $scope.columns.length + 1;
16 | $scope.columns.push({'id': 'col' + newItemNo});
17 | };
18 | $scope.removeLastCol = Tables.removeLastCol;
19 | $scope.removeLastCol = function() {
20 | $scope.columns.pop();
21 | };
22 | $scope.addNewTable = function() {
23 | Tables.addNewTable($scope.name, $scope.columns, $scope.contains, $scope.depends);
24 | $scope.name = '';
25 | $scope.columns = [{id: 'col1'}];
26 | $scope.contains = null;
27 | $scope.depends = null;
28 | $scope.tables = Tables.tables;
29 | $scope.tableName1 = {};
30 | $scope.tableName = {};
31 | };
32 | $scope.updateDependency = function() {
33 | $scope.depends = $scope.tableName1.name;
34 | };
35 | $scope.updateContains = function() {
36 | $scope.contains = $scope.tableName.name;
37 | };
38 | $scope.createSql = function() {
39 | $scope.sqlString = Tables.createSql();
40 | }
41 | }])
42 | .factory('Tables', function() {
43 | String.prototype.insert = function (index, string) {
44 | if (index > 0)
45 | return this.substring(0, index) + string + this.substring(index, this.length);
46 | else
47 | return string + this;
48 | };
49 | var tables = [];
50 | var sqlString = '';
51 | var addNewTable = function(name, columns, contains, depends) {
52 | sqlString += "CREATE TABLE " + "`" + name + "` (\n" +
53 | "`" + name + "Id`" + " INT NOT NULL AUTO_INCREMENT,\n";
54 | for (var y = 0, newCount = columns.length; y < newCount; y++) {
55 | sqlString += "`" + columns[y].name + "`" + " VARCHAR(45) NULL, "
56 | }
57 | columns.push({name: name + "Id"});
58 | if (contains === null && depends !== null) {
59 | sqlString += "`" + depends + "Id` INT NULL,\n";
60 | sqlString += "PRIMARY KEY (`" + name + "Id`), ";
61 | sqlString += "INDEX `" + depends + "Id_idx` (`" + depends + "Id` ASC),\n";
62 | sqlString += "CONSTRAINT `" + depends + "Id`\n";
63 | sqlString += "FOREIGN KEY (`" + depends + "Id`)\n";
64 | sqlString += "REFERENCES `" + depends + "` (`" + depends + "Id`)\n";
65 | columns.push({name: depends + 'Id' + '(FK) '});
66 | }
67 | else if (contains !== null && depends === null) {
68 | for (var x = 0, count = tables.length; x < count; x++) {
69 | if (contains === tables[x].name) {
70 | var index = sqlString.indexOf("PRIMARY KEY (`" + contains + "Id`)") - 1;
71 | var newString = " `" + name + "Id` INT NULL,\n";
72 | newString += "INDEX `" + name + "Id_idx` (`" + name + "Id` ASC),\n";
73 | newString += "CONSTRAINT `" + name + "Id`\n";
74 | newString += "FOREIGN KEY (`" + name + "Id`)\n";
75 | newString += "REFERENCES `" + name + "` (`" + name + "Id`),\n";
76 | sqlString = sqlString.insert(index, newString) + "PRIMARY KEY (`" + name + "Id`)";
77 | tables[x].columns.push({name: name + "Id" + '(FK)'});
78 | }
79 | }
80 | }
81 | else {
82 | sqlString += "PRIMARY KEY (`" + name + "Id`)";
83 | }
84 | if (contains !== null && depends !== null) {
85 | if (contains === depends) {
86 | sqlString += ");";
87 | sqlString += "CREATE TABLE `" + contains + name + "` ( ";
88 | sqlString += "`" + contains + name + "Id` INT NOT NULL AUTO_INCREMENT, ";
89 | sqlString += "`" + contains + "Id` INT NULL, ";
90 | sqlString += "`" + name + "Id` INT NULL, ";
91 | sqlString += "PRIMARY KEY (`" + contains + name + "Id`), ";
92 | sqlString += "INDEX `" + contains + "Id_idx` (`" + contains + "Id` ASC), ";
93 | sqlString += "INDEX `" + name + "Id_idx` (`" + name + "Id` ASC), ";
94 | sqlString += "CONSTRAINT `" + contains + "Id` ";
95 | sqlString += "FOREIGN KEY (`" + contains + "Id`) ";
96 | sqlString += "REFERENCES `" + contains + "` (`" + contains + "Id`), ";
97 | sqlString += "CONSTRAINT `" + name + "Id` ";
98 | sqlString += "FOREIGN KEY (`" + name + "Id`) ";
99 | sqlString += "REFERENCES `" + name + "` (`" + name + "Id`)";
100 | tables.push({
101 | name: contains + name,
102 | columns: [{name: contains + name + "Id"}, {name: contains + "Id" + '(FK)'}, {name: name + "Id" + '(FK)'}]
103 | })
104 | }
105 | }
106 |
107 | sqlString += "); ";
108 | tables.push({name: name, columns: columns});
109 | };
110 | var createSql = function() {
111 | return sqlString;
112 | };
113 |
114 | return {
115 | tables: tables,
116 | sqlString: sqlString,
117 | createSql: createSql,
118 | addNewTable: addNewTable
119 | }
120 | });
--------------------------------------------------------------------------------
/.idea/dbnavigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
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 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
--------------------------------------------------------------------------------