Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Commit cf82b98

Browse files
author
Dror Matalon
committed
* Mostly working correctly.
* Added tab with the db schema
1 parent 462c707 commit cf82b98

File tree

14 files changed

+314
-212
lines changed

14 files changed

+314
-212
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ This is an initial implementation of Meteor SQL. It currently only supports MySQ
3737

3838
# Future
3939
* Support joins
40+
* Support prepared statements
4041
* Support views
41-
* Handle transactions (possible, but
42+
* Handle transactions. It's possible right now, but make it cleaner.

TODO.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
* JSDOC
2-
* Improve the UI for insert, update, delete
3-
* various data types
4-
* Create a tab showing all the tables and columns
5-
* Migrate to use http://hiddentao.github.com/squel/
2+
* Move everything to the SQL dir
3+
* Install the driver locally
4+
* Deploy to devwik
65

76
#Later
87
* Bugs: * Race condition: remove after insert fails cause insert didn't finish
98
* How do we deal with large number of rows. We don't want to insert a huge number of rows
109
* Don't create tables, triggers, etc automatically each time?
10+
* Run forever on the server

client/employee.html

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<template name="devwikEmployees">
2+
<div>
3+
<div class='row'>
4+
<div class= 'span9 offset2'
5+
<form class="form-inline">
6+
<input id='inputFirst' type="text" class="input-small" placeholder="First">
7+
<input id='inputLast' type="text" class="input-small" placeholder="Last">
8+
<input id='inputTitle' type="text" class="input-small" placeholder="Title">
9+
<input id='inputEmail' type="text" class="input-small" placeholder="Email">
10+
<button id ="insert" class="btn btn">Insert</button>
11+
<div id='insertResult'> </div>
12+
</form>
13+
<form class="form-inline">
14+
<input id='updateFirst' type="text" class="input-small" placeholder="First">
15+
<input id='updateLast' type="text" class="input-small" placeholder="Last">
16+
<input id='updateTitle' type="text" class="input-small" placeholder="Title">
17+
<input id='updateEmail' type="text" class="input-small" placeholder="Email">
18+
<select id='updateId'>
19+
{{#each eSelects}}
20+
{{> eSelect}}
21+
{{/each}}
22+
</select>
23+
<button id="update" class="btn btn">Update</button>
24+
<div id='insertResult'> </div>
25+
</form>
26+
27+
</div>
28+
</div>
29+
</div>
30+
{{> employeeRows}}
31+
</template>
32+
33+
<template name="employeeRows">
34+
<div class='row'>
35+
<h4>
36+
<div class='span1'>
37+
</div>
38+
<div class='span1'>
39+
Id
40+
</div>
41+
<div class='span2'>
42+
First
43+
</div>
44+
<div class='span2'>
45+
Last
46+
</div>
47+
<div class='span2'>
48+
Title
49+
</div>
50+
<div class='span2'>
51+
Email
52+
</div>
53+
</h4>
54+
</div>
55+
{{#each employees}}
56+
{{> employee}}
57+
{{/each}}
58+
</template>
59+
60+
61+
<template name="employee">
62+
<div id={{employeeNumber}} class='row'>
63+
<div class='span1'>
64+
<button onclick='deleteEmployee({{employeeNumber}})'
65+
class="deleteRow btn btn-mini btn-danger">
66+
<i class="icon-trash icon-white"></i>
67+
delete</button>
68+
</div>
69+
<div class='span1'>
70+
{{employeeNumber}}
71+
</div>
72+
<div class='span2'>
73+
{{firstName}}
74+
</div>
75+
<div class='span2'>
76+
{{lastName}}
77+
</div>
78+
<div class='span2'>
79+
{{jobTitle}}
80+
</div>
81+
<div class='span2'>
82+
{{email}}
83+
</div>
84+
</div>
85+
</template>
86+
87+
88+
<template name="eSelect">
89+
<option value="{{employeeNumber}}">{{employeeNumber}}</option>
90+
</template>

client/employee.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var notDone = true;
2+
var Employee = new Meteor.Table('employees');
3+
Meteor.subscribe('meteor_tables');
4+
var Tables = new Meteor.Collection('meteor_tables');
5+
6+
Template.devwikEmployees.rendered = function () {
7+
if (notDone) {//do it once
8+
notDone = false;
9+
Devwik.Utils.clickButton('#insert', function(event) {
10+
var insert = {};
11+
insert.firstName = $('#inputFirst').val();
12+
insert.lastName = $('#inputLast').val();
13+
insert.email = $('#inputEmail').val();
14+
insert.jobTitle = $('#inputTitle').val();
15+
console.log(insert);
16+
Employee.insert(insert, function(err, value) {
17+
if (err) {
18+
alert(_.values(err));
19+
} else {
20+
$('#insertResult').html('Inserted:' + value);
21+
console.log(value);
22+
}
23+
});
24+
});
25+
26+
Devwik.Utils.clickButton('#update', function(event) {
27+
var id= $('#updateId').val();
28+
update = {};
29+
update.firstName = $('#updateFirst').val();
30+
update.lastName = $('#updateLast').val();
31+
update.email = $('#updateEmail').val();
32+
update.jobTitle = $('#updateTitle').val();
33+
var criteria = 'employeeNumber =' + id;
34+
Employee.update(update, criteria, function(err, value) {
35+
if (err) {
36+
alert(_.values(err));
37+
} else {
38+
console.log(value);
39+
}
40+
});
41+
return(false);
42+
});
43+
44+
Devwik.Utils.clickButton('#remove', function(event) {
45+
var remove= $('#fieldRemove').val();
46+
console.log(remove);
47+
Employee.remove(remove, function(err, value) {
48+
if (err) {
49+
alert(_.values(err));
50+
} else {
51+
$('#deleteResult').html('Deleted:' + value.affectedRows);
52+
console.log(value);
53+
}
54+
});
55+
});
56+
57+
}
58+
};
59+
60+
Template.employeeRows.employees = function () {
61+
return Employee.find({}, {sort: {employeeNumber: -1}});
62+
};
63+
64+
Template.devwikEmployees.eSelects = function () {
65+
return Employee.find({}, {sort: {employeeNumber: -1}});
66+
};
67+
68+
69+
function deleteEmployee(number) {
70+
console.log('remove:' + number);
71+
Employee.remove('where employeeNumber =' + number, function(err, value) {
72+
if (err) {
73+
alert(_.values(err));
74+
}
75+
});
76+
}

client/lib/sql/collections.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Meteor.Table = function(name) {
33
Meteor.subscribe(name);
44
var myCollection = new Meteor.Collection(name);
55

6-
//TODO test callback
76
myCollection.insert = function (args, callback) {
87
Meteor.call('SQLinsert', this._name, args, callback);
98
};
109

11-
myCollection.update = function (criteria, callback) {
10+
myCollection.update = function (args, criteria, callback) {
1211
try {
13-
Meteor.call('SQLupdate', this._name, criteria, callback);
12+
Meteor.call('SQLupdate', this._name, args, criteria, callback);
13+
console.log('after update');
1414
} catch (err) {
1515
console.log(err);
1616
}
@@ -23,7 +23,6 @@ Meteor.Table = function(name) {
2323
console.log(err);
2424
}
2525
};
26-
console.log(myCollection);
2726
return(myCollection);
2827
};
2928

client/main.html

Lines changed: 19 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,75 +9,27 @@
99
}
1010
</style>
1111

12-
</head>
13-
14-
<body>
15-
<div class="container">
16-
<h1> Meteor SQL </h1>
17-
<form >
18-
<fieldset>
19-
<div class='formFields' id="{{args.inputId}}">
20-
{{#each formFields}}
21-
{{> formField}}
22-
{{/each}}
23-
</div>
24-
<div class="control-group">
25-
<div class="controls">
26-
<input id='fieldInsert' type="text" class="input">
27-
28-
<button id ="insert" class="btn btn-large btn">Insert</button>
29-
<div id='insertResult'> </div>
30-
</div>
31-
</div>
32-
<div class="control-group">
33-
<div class="controls">
34-
<input id='fieldUpdate' type="text" class="input">
35-
36-
<button id ="update" class="btn btn-large btn">Update</button>
37-
<div id='updateResult'> </div>
38-
</div>
39-
</div>
40-
<div class="control-group">
41-
<div class="controls">
42-
<input id='fieldRemove' type="text" class="input">
43-
44-
<button id ="remove" class="btn btn-large btn">Delete</button>
45-
<div id='deleteResult'> </div>
12+
</head>
13+
14+
<body>
15+
<div class="container">
16+
<h1> Meteor SQL </h1>
17+
<ul class="nav nav-pills" id="formBuilderTabs">
18+
<li ><a data-toggle='pill' href="#employeeTable">Employee Table</a></li>
19+
<li class='active' ><a data-toggle='pill' href="#schema">Database Schema</a></li>
20+
</ul>
21+
22+
<div class="pill-content">
23+
<div class="pill-pane " id="employeeTable">
24+
<div class='row'>
25+
{{> devwikEmployees}}
26+
</div>
4627
</div>
28+
<div class="pill-pane active" id="schema">
29+
{{> devwikTables}}
4730
</div>
48-
</fieldset>
49-
</form>
50-
51-
{{> show}}
52-
</div>
53-
</body>
54-
55-
<template name="show">
56-
<div class='row'>
57-
<h4>
58-
<div class='span2'>
59-
id
60-
</div>
61-
<div class='span2'>
62-
b
6331
</div>
64-
</h4>
65-
</div>
66-
{{#each rows}}
67-
{{> row}}
68-
{{/each}}
69-
</template>
70-
71-
72-
<template name="row">
73-
<div class='row'>
74-
<h5>
75-
<div class='span2'>
76-
{{a}}
77-
</div>
78-
<div class='span2'>
79-
{{b}}</h5>
8032
</div>
81-
</h5>
82-
</template>
8333

34+
35+
</body>

client/main.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

common/lib/vendor/squel.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Generated by CoffeeScript 1.3.3
2-
31
/*
42
Copyright (c) 2012 Ramesh Nair (hiddentao.com)
53
@@ -803,6 +801,9 @@ OTHER DEALINGS IN THE SOFTWARE.
803801
"delete": function(options) {
804802
return new Delete(options);
805803
},
804+
remove: function(options) {
805+
return new Delete(options);
806+
},
806807
DefaultQueryBuilderOptions: DefaultQueryBuilderOptions,
807808
Cloneable: Cloneable,
808809
Expression: Expression,

0 commit comments

Comments
 (0)