Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

removed accidental leading space on these files

  • Loading branch information...
commit 120ca3cefb5449e3f1e92c260bcc3d159066e3cb 1 parent c726a12
John Atten authored December 02, 2013
310  test/mysql_queries_spec.coffee
... ...
@@ -1,156 +1,156 @@
1  
- massive = require("../index")
2  
- should = require("should")
3  
- util = require("util")
4  
- helper = require('./mysql_helper')
5  
-
6  
- describe "MySQL Queries", ->
7  
-   db = null
8  
-   before (done) ->
9  
-     massive.connect helper.connectionString(), (err,_db) ->
10  
-       db = _db
11  
-       done()
12  
-
13  
-   describe "initialization", ->
14  
-
15  
-     it "sets the table name", ->
16  
-       db.products.name.should.equal("products")
17  
-
18  
-     it "defaults the pk to id",  ->
19  
-       db.products.pk.should.equal("id")
20  
-
21  
-
22  
-   describe "SELECT queries", ->
23  
-     it "runs a select *", ->
24  
-       query = db.products.find()
25  
-       query.sql.should.equal "SELECT * FROM products"
26  
-       query.params.length.should.equal 0
27  
-
28  
-     it "adds columns when specified",  ->
29  
-       query = db.products.find ["name"]
30  
-       query.sql.should.equal "SELECT name FROM products"
31  
-
32  
-     it "adds columns when specified in criteria",  ->
33  
-       query = db.products.find {}, {columns : "name"}
34  
-       query.sql.should.equal "SELECT name FROM products"
35  
-       query.params.length.should.equal 0
36  
-
37  
-     it "adds a where when id is a number", ->
38  
-       query = db.products.find {id : 1}
39  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 1")
40  
-       query.params.length.should.equal 0
41  
-
42  
-     it "adds a where as a primary key", ->
43  
-       query = db.products.find(5)
44  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5")
45  
-       query.params.length.should.equal 0
46  
-
47  
-
48  
-     it "adds a LIMIT if specified", ->
49  
-       query = db.products.find(5).limit(1)
50  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nLIMIT 1")
51  
-
52  
-     it "adds a LIMIT with SKIP if specified", ->
53  
-       query = db.products.find(5).limit(10,1)
54  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nLIMIT 10 OFFSET 1")
55  
-
56  
-     it "adds an ORDER if specified", ->
57  
-       query = db.products.find(5).order("name")
58  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nORDER BY name")
59  
-
60  
-     it "handles greater than", ->
61  
-       query = db.products.find({"id >" : "steve"})
62  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" > ?")
63  
-       query.params.length.should.equal 1
64  
-
65  
-     it "handles less than", ->
66  
-       query = db.products.find({"id <" : "steve"})
67  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" < ?")
68  
-       query.params.length.should.equal 1
69  
-
70  
-     it "handles bang equal", ->
71  
-       query = db.products.find({"id !=" : "steve"})
72  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> ?")
73  
-       query.params.length.should.equal 1
74  
-
75  
-     it "handles ineqaulity", ->
76  
-       query = db.products.find({"id <>" : "steve"})
77  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> ?")
78  
-       query.params.length.should.equal 1
79  
-
80  
-     it "handles IN", ->
81  
-       query = db.products.find({id : ["steve","juice","pete"]})
82  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" IN (?, ?, ?)")
83  
-       query.params.length.should.equal 3
84  
-
85  
-     it "handles NOT IN", ->
86  
-       query = db.products.find({"id != ": ["steve","juice","pete"]})
87  
-       query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" NOT IN (?, ?, ?)")
88  
-       query.params.length.should.equal 3
89  
-
90  
-     it "handles inline goodness", ->
91  
-       query = db.run("select * from crazytown where id = ?", [1])
92  
-       query.sql.should.equal("select * from crazytown where id = ?")
93  
-       query.params.length.should.equal 1
94  
-
95  
-   describe "destroy", ->
96  
-     it "creates a delete everything", ->
97  
-       query = db.products.destroy()
98  
-       query.sql.should.equal "DELETE FROM products"
99  
-       query.params.length.should.equal 0
100  
-
101  
-     it "uses where when specified as an argument", ->
102  
-       query = db.products.destroy({id : 1})
103  
-       query.sql.should.equal "DELETE FROM products \nWHERE \"id\" = 1"
104  
-       query.params.length.should.equal 0
105  
-
106  
-
107  
-     it "adds a where as a primary key", ->
108  
-       query = db.products.destroy(6)
109  
-       query.sql.should.equal("DELETE FROM products \nWHERE \"id\" = 6")
110  
-       query.params.length.should.equal 0
111  
-
112  
-   describe "insert", ->
113  
-     it "creates a basic insert with returning", ->
114  
-       query = db.products.insert({name : "steve", price : 12.00})
115  
-       query.sql.should.equal "INSERT INTO products (name, price) VALUES\n(?, ?)"
116  
-       query.params.length.should.equal 2
117  
-
118  
-     it "creates a batch for item arrays", ->
119  
-       items = [{title:"stuffy stuff", price: 12.00, desc : "bubble"},{title:"poofy poof", price: 24.00, desc : "glurp"}]
120  
-       query = db.products.insert(items)
121  
-       query.sql.should.equal "INSERT INTO products (title, price, desc) VALUES\n(?, ?, ?),\n(?, ?, ?)"
122  
-       query.params.length.should.equal 6
123  
-
124  
-     it "throws an error if no data was supplied", ->
125  
-       (-> db.products.insert().execute()).should.throw
126  
-
127  
-   describe "updates", ->
128  
-     it "creates a basic update", ->
129  
-       query = db.products.update({name:"pumpkin", price:1000}, 12)
130  
-       query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" = 12")
131  
-       query.params.length.should.equal 2
132  
-
133  
-     it "creates a basic update with a string key", ->
134  
-       query = db.products.update({name:"pumpkin", price:1000}, "12")
135  
-       query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" = ?")
136  
-       query.params.length.should.equal 3
137  
-
138  
-     it "creates a basic update with multi result", ->
139  
-       query = db.products.update({name:"pumpkin", price:1000}, {"id >": 12})
140  
-       query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" > 12")
141  
-       query.params.length.should.equal 2
142  
-
143  
-     it "updates all rows", ->
144  
-       query = db.products.update({name:"leto", sand: true})
145  
-       query.sql.should.equal("UPDATE products SET name = ?, sand = ?")
146  
-       query.params.length.should.equal 2
147  
-
148  
-
149  
-   describe "aggregates", ->
150  
-     it "counts with SELECT COUNT", ->
151  
-       query = db.products.count()
152  
-       query.sql.should.equal("SELECT COUNT(1) FROM products")
153  
-     it "counts with SELECT COUNT and a WHERE", ->
154  
-       query = db.products.count({"id > " : 1})
155  
-       query.sql.should.equal("SELECT COUNT(1) FROM products \nWHERE \"id\" > 1")
  1
+massive = require("../index")
  2
+should = require("should")
  3
+util = require("util")
  4
+helper = require('./mysql_helper')
  5
+
  6
+describe "MySQL Queries", ->
  7
+  db = null
  8
+  before (done) ->
  9
+    massive.connect helper.connectionString(), (err,_db) ->
  10
+      db = _db
  11
+      done()
  12
+
  13
+  describe "initialization", ->
  14
+
  15
+    it "sets the table name", ->
  16
+      db.products.name.should.equal("products")
  17
+
  18
+    it "defaults the pk to id",  ->
  19
+      db.products.pk.should.equal("id")
  20
+
  21
+
  22
+  describe "SELECT queries", ->
  23
+    it "runs a select *", ->
  24
+      query = db.products.find()
  25
+      query.sql.should.equal "SELECT * FROM products"
  26
+      query.params.length.should.equal 0
  27
+
  28
+    it "adds columns when specified",  ->
  29
+      query = db.products.find ["name"]
  30
+      query.sql.should.equal "SELECT name FROM products"
  31
+
  32
+    it "adds columns when specified in criteria",  ->
  33
+      query = db.products.find {}, {columns : "name"}
  34
+      query.sql.should.equal "SELECT name FROM products"
  35
+      query.params.length.should.equal 0
  36
+
  37
+    it "adds a where when id is a number", ->
  38
+      query = db.products.find {id : 1}
  39
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 1")
  40
+      query.params.length.should.equal 0
  41
+
  42
+    it "adds a where as a primary key", ->
  43
+      query = db.products.find(5)
  44
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5")
  45
+      query.params.length.should.equal 0
  46
+
  47
+
  48
+    it "adds a LIMIT if specified", ->
  49
+      query = db.products.find(5).limit(1)
  50
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nLIMIT 1")
  51
+
  52
+    it "adds a LIMIT with SKIP if specified", ->
  53
+      query = db.products.find(5).limit(10,1)
  54
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nLIMIT 10 OFFSET 1")
  55
+
  56
+    it "adds an ORDER if specified", ->
  57
+      query = db.products.find(5).order("name")
  58
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" = 5 \nORDER BY name")
  59
+
  60
+    it "handles greater than", ->
  61
+      query = db.products.find({"id >" : "steve"})
  62
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" > ?")
  63
+      query.params.length.should.equal 1
  64
+
  65
+    it "handles less than", ->
  66
+      query = db.products.find({"id <" : "steve"})
  67
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" < ?")
  68
+      query.params.length.should.equal 1
  69
+
  70
+    it "handles bang equal", ->
  71
+      query = db.products.find({"id !=" : "steve"})
  72
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> ?")
  73
+      query.params.length.should.equal 1
  74
+
  75
+    it "handles ineqaulity", ->
  76
+      query = db.products.find({"id <>" : "steve"})
  77
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" <> ?")
  78
+      query.params.length.should.equal 1
  79
+
  80
+    it "handles IN", ->
  81
+      query = db.products.find({id : ["steve","juice","pete"]})
  82
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" IN (?, ?, ?)")
  83
+      query.params.length.should.equal 3
  84
+
  85
+    it "handles NOT IN", ->
  86
+      query = db.products.find({"id != ": ["steve","juice","pete"]})
  87
+      query.sql.should.equal("SELECT * FROM products \nWHERE \"id\" NOT IN (?, ?, ?)")
  88
+      query.params.length.should.equal 3
  89
+
  90
+    it "handles inline goodness", ->
  91
+      query = db.run("select * from crazytown where id = ?", [1])
  92
+      query.sql.should.equal("select * from crazytown where id = ?")
  93
+      query.params.length.should.equal 1
  94
+
  95
+  describe "destroy", ->
  96
+    it "creates a delete everything", ->
  97
+      query = db.products.destroy()
  98
+      query.sql.should.equal "DELETE FROM products"
  99
+      query.params.length.should.equal 0
  100
+
  101
+    it "uses where when specified as an argument", ->
  102
+      query = db.products.destroy({id : 1})
  103
+      query.sql.should.equal "DELETE FROM products \nWHERE \"id\" = 1"
  104
+      query.params.length.should.equal 0
  105
+
  106
+
  107
+    it "adds a where as a primary key", ->
  108
+      query = db.products.destroy(6)
  109
+      query.sql.should.equal("DELETE FROM products \nWHERE \"id\" = 6")
  110
+      query.params.length.should.equal 0
  111
+
  112
+  describe "insert", ->
  113
+    it "creates a basic insert with returning", ->
  114
+      query = db.products.insert({name : "steve", price : 12.00})
  115
+      query.sql.should.equal "INSERT INTO products (name, price) VALUES\n(?, ?)"
  116
+      query.params.length.should.equal 2
  117
+
  118
+    it "creates a batch for item arrays", ->
  119
+      items = [{title:"stuffy stuff", price: 12.00, desc : "bubble"},{title:"poofy poof", price: 24.00, desc : "glurp"}]
  120
+      query = db.products.insert(items)
  121
+      query.sql.should.equal "INSERT INTO products (title, price, desc) VALUES\n(?, ?, ?),\n(?, ?, ?)"
  122
+      query.params.length.should.equal 6
  123
+
  124
+    it "throws an error if no data was supplied", ->
  125
+      (-> db.products.insert().execute()).should.throw
  126
+
  127
+  describe "updates", ->
  128
+    it "creates a basic update", ->
  129
+      query = db.products.update({name:"pumpkin", price:1000}, 12)
  130
+      query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" = 12")
  131
+      query.params.length.should.equal 2
  132
+
  133
+    it "creates a basic update with a string key", ->
  134
+      query = db.products.update({name:"pumpkin", price:1000}, "12")
  135
+      query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" = ?")
  136
+      query.params.length.should.equal 3
  137
+
  138
+    it "creates a basic update with multi result", ->
  139
+      query = db.products.update({name:"pumpkin", price:1000}, {"id >": 12})
  140
+      query.sql.should.equal("UPDATE products SET name = ?, price = ? \nWHERE \"id\" > 12")
  141
+      query.params.length.should.equal 2
  142
+
  143
+    it "updates all rows", ->
  144
+      query = db.products.update({name:"leto", sand: true})
  145
+      query.sql.should.equal("UPDATE products SET name = ?, sand = ?")
  146
+      query.params.length.should.equal 2
  147
+
  148
+
  149
+  describe "aggregates", ->
  150
+    it "counts with SELECT COUNT", ->
  151
+      query = db.products.count()
  152
+      query.sql.should.equal("SELECT COUNT(1) FROM products")
  153
+    it "counts with SELECT COUNT and a WHERE", ->
  154
+      query = db.products.count({"id > " : 1})
  155
+      query.sql.should.equal("SELECT COUNT(1) FROM products \nWHERE \"id\" > 1")
156 156
 
106  test/mysql_schema_spec.coffee
... ...
@@ -1,53 +1,53 @@
1  
- massive = require("../index")
2  
- should = require("should")
3  
- util = require("util")
4  
- helper = require('./mysql_helper')
5  
-
6  
- describe "schema queries", ->
7  
-   db = null
8  
-   before (done) ->
9  
-      massive.connect helper.connectionString(), (err,_db) ->
10  
-       db = _db
11  
-       done()
12  
-
13  
-   it "should exist", ->
14  
-     should.exist db
15  
-
16  
-   describe "dropTable", ->
17  
-     it "creates a drop statement", ->
18  
-       db.dropTable("cheese").sql.should.equal("DROP TABLE IF EXISTS cheese;")
19  
-
20  
-   describe "create table", ->
21  
-
22  
-     it "adds a column with NULL declaration", ->
23  
-       query = db.createTable "cheese", {bucket:"beef NOT NULL PLEASE"}
24  
-       query.sql.indexOf("bucket beef NOT NULL PLEASE").should.be.greaterThan(0)
25  
-
26  
-     it "adds primary key by default", ->
27  
-       query = db.createTable "cheese",{title:"string"}
28  
-       query.sql.indexOf("INT NOT NULL PRIMARY KEY AUTO_INCREMENT").should.be.greaterThan(0)
29  
-
30  
-     it "adds a varchar 255 for string", ->
31  
-       query = db.createTable "cheese",{title:"string"}
32  
-       query.sql.indexOf("title varchar(255)").should.be.greaterThan(0)
33  
-
34  
-     it "adds a varchar 255 for string with null", ->
35  
-       query = db.createTable "cheese",{title:"string null"}
36  
-       query.sql.indexOf("title varchar(255) null").should.be.greaterThan(0)
37  
-
38  
-     it "adds a decimal(8,2) for money", ->
39  
-       query = db.createTable "cheese",{price:"money"}
40  
-       query.sql.indexOf("price decimal(8,2)").should.be.greaterThan(0)
41  
-
42  
-     it "adds a datetime for date", ->
43  
-       query = db.createTable "cheese",{created:"date"}
44  
-       console.log(query.sql)
45  
-       query.sql.indexOf("created datetime").should.be.greaterThan(0)
46  
-
47  
-     it "adds a bool for... bool", ->
48  
-       query = db.createTable "cheese",{stuff:"bool"}
49  
-       query.sql.indexOf("stuff bool").should.be.greaterThan(0)
50  
-
51  
-     it "adds created and updated for timestamps", ->
52  
-       query = db.createTable "cheese",{timestamps:true}
53  
-       query.sql.indexOf("created_at datetime,updated_at timestamp").should.be.greaterThan(0)
  1
+massive = require("../index")
  2
+should = require("should")
  3
+util = require("util")
  4
+helper = require('./mysql_helper')
  5
+
  6
+describe "schema queries", ->
  7
+  db = null
  8
+  before (done) ->
  9
+     massive.connect helper.connectionString(), (err,_db) ->
  10
+      db = _db
  11
+      done()
  12
+
  13
+  it "should exist", ->
  14
+    should.exist db
  15
+
  16
+  describe "dropTable", ->
  17
+    it "creates a drop statement", ->
  18
+      db.dropTable("cheese").sql.should.equal("DROP TABLE IF EXISTS cheese;")
  19
+
  20
+  describe "create table", ->
  21
+
  22
+    it "adds a column with NULL declaration", ->
  23
+      query = db.createTable "cheese", {bucket:"beef NOT NULL PLEASE"}
  24
+      query.sql.indexOf("bucket beef NOT NULL PLEASE").should.be.greaterThan(0)
  25
+
  26
+    it "adds primary key by default", ->
  27
+      query = db.createTable "cheese",{title:"string"}
  28
+      query.sql.indexOf("INT NOT NULL PRIMARY KEY AUTO_INCREMENT").should.be.greaterThan(0)
  29
+
  30
+    it "adds a varchar 255 for string", ->
  31
+      query = db.createTable "cheese",{title:"string"}
  32
+      query.sql.indexOf("title varchar(255)").should.be.greaterThan(0)
  33
+
  34
+    it "adds a varchar 255 for string with null", ->
  35
+      query = db.createTable "cheese",{title:"string null"}
  36
+      query.sql.indexOf("title varchar(255) null").should.be.greaterThan(0)
  37
+
  38
+    it "adds a decimal(8,2) for money", ->
  39
+      query = db.createTable "cheese",{price:"money"}
  40
+      query.sql.indexOf("price decimal(8,2)").should.be.greaterThan(0)
  41
+
  42
+    it "adds a datetime for date", ->
  43
+      query = db.createTable "cheese",{created:"date"}
  44
+      console.log(query.sql)
  45
+      query.sql.indexOf("created datetime").should.be.greaterThan(0)
  46
+
  47
+    it "adds a bool for... bool", ->
  48
+      query = db.createTable "cheese",{stuff:"bool"}
  49
+      query.sql.indexOf("stuff bool").should.be.greaterThan(0)
  50
+
  51
+    it "adds created and updated for timestamps", ->
  52
+      query = db.createTable "cheese",{timestamps:true}
  53
+      query.sql.indexOf("created_at datetime,updated_at timestamp").should.be.greaterThan(0)
48  test/mysql_spec.coffee
... ...
@@ -1,30 +1,30 @@
1  
- massive = require("../index")
2  
- should = require("should")
3  
- util = require("util")
4  
- helper = require('./mysql_helper')
  1
+massive = require("../index")
  2
+should = require("should")
  3
+util = require("util")
  4
+helper = require('./mysql_helper')
5 5
 
6  
- describe "Connections", ->
7  
-   db = null
8  
-   before (done) ->
9  
-     massive.connect helper.connectionString(), (err,_db) ->
10  
-       db = _db
11  
-       done()
  6
+describe "Connections", ->
  7
+  db = null
  8
+  before (done) ->
  9
+    massive.connect helper.connectionString(), (err,_db) ->
  10
+      db = _db
  11
+      done()
12 12
 
13  
-   it "returns a new postgres db", ->
14  
-     should.exist db
  13
+  it "returns a new MySql db", ->
  14
+    should.exist db
15 15
 
16  
-   it "has a tables array", ->
17  
-     should.exist db.tables
  16
+  it "has a tables array", ->
  17
+    should.exist db.tables
  18
+ 
  19
+  it "sets dbType to MySql", ->
  20
+    db.dbType.should.equal("MySQL")
18 21
 
19  
-   it "sets dbType to PostgreSQL", ->
20  
-     db.dbType.should.equal("MySQL")
  22
+  it "loads tables with name and pk", ->
  23
+    db.tables.length.should.be.greaterThan 0
21 24
 
22  
-   it "loads tables with name and pk", ->
23  
-     db.tables.length.should.be.greaterThan 0
  25
+  #this requires a products table in the test db
  26
+  it "grafts the tables onto the query", ->
  27
+    should.exist db.products
24 28
 
25  
-   #this requires a products table in the test db
26  
-   it "grafts the tables onto the query", ->
27  
-     should.exist db.products
28  
-
29  
-   it "returns the pk", ->
30  
-     db.products.pk.should.equal("id")
  29
+  it "returns the pk", ->
  30
+    db.products.pk.should.equal("id")

0 notes on commit 120ca3c

Please sign in to comment.
Something went wrong with that request. Please try again.