@typetron/framework 0.5.0 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/build/Database/EntityProxyHandler.js +2 -2
  2. package/build/Database/EntityProxyHandler.js.map +1 -1
  3. package/package.json +4 -7
  4. package/.eslintrc-old.js +0 -208
  5. package/Cache/Cache.ts +0 -13
  6. package/Cache/Stores/DatabaseStore.ts +0 -120
  7. package/Cache/Stores/FileStore.ts +0 -69
  8. package/Cache/Stores/MemoryStore.ts +0 -71
  9. package/Cache/index.ts +0 -5
  10. package/Cache/types.ts +0 -4
  11. package/Container/ClassResolver.ts +0 -106
  12. package/Container/Container.ts +0 -144
  13. package/Container/Contracts.ts +0 -3
  14. package/Container/Decorators.ts +0 -20
  15. package/Container/Metadata.ts +0 -16
  16. package/Container/Resolver.ts +0 -27
  17. package/Container/index.ts +0 -5
  18. package/Database/Clauses/Where.ts +0 -0
  19. package/Database/Connection.ts +0 -52
  20. package/Database/Decorators.ts +0 -142
  21. package/Database/Drivers/DatabaseDriver.ts +0 -37
  22. package/Database/Drivers/MySQL/Alter/index.ts +0 -55
  23. package/Database/Drivers/MySQL/ColumnDefinition.ts +0 -16
  24. package/Database/Drivers/MySQL/Create.ts +0 -47
  25. package/Database/Drivers/MySQL/MysqlDriver.ts +0 -123
  26. package/Database/Drivers/MySQL/Schema.ts +0 -82
  27. package/Database/Drivers/MySQL/index.ts +0 -13
  28. package/Database/Drivers/SQL/Schema.ts +0 -73
  29. package/Database/Drivers/SQL/Statements/Alter.ts +0 -22
  30. package/Database/Drivers/SQL/Statements/BaseStatement.ts +0 -55
  31. package/Database/Drivers/SQL/Statements/Delete.ts +0 -20
  32. package/Database/Drivers/SQL/Statements/Insert.ts +0 -24
  33. package/Database/Drivers/SQL/Statements/Select.ts +0 -55
  34. package/Database/Drivers/SQL/Statements/Update.ts +0 -33
  35. package/Database/Drivers/SQL/index.ts +0 -8
  36. package/Database/Drivers/SQLite/Create.ts +0 -45
  37. package/Database/Drivers/SQLite/Schema.ts +0 -54
  38. package/Database/Drivers/SQLite/SqliteDriver.ts +0 -144
  39. package/Database/Drivers/SQLite/index.ts +0 -15
  40. package/Database/Drivers/SchemaContract.ts +0 -11
  41. package/Database/Drivers/Statement.ts +0 -16
  42. package/Database/Drivers/index.ts +0 -4
  43. package/Database/Entity.ts +0 -377
  44. package/Database/EntityNotFoundError.ts +0 -5
  45. package/Database/EntityProxyHandler.ts +0 -43
  46. package/Database/EntityQuery.ts +0 -197
  47. package/Database/Expression.ts +0 -3
  48. package/Database/Fields.ts +0 -816
  49. package/Database/Helpers.ts +0 -12
  50. package/Database/List.ts +0 -71
  51. package/Database/Migrations/Migration.ts +0 -10
  52. package/Database/Migrations/MigrationHistory.ts +0 -20
  53. package/Database/Migrations/Migrator.ts +0 -122
  54. package/Database/Migrations/index.ts +0 -3
  55. package/Database/ORM/BaseRelationship.ts +0 -10
  56. package/Database/Query.ts +0 -374
  57. package/Database/Seeders/Seeder.ts +0 -3
  58. package/Database/Seeders/SeederManager.ts +0 -27
  59. package/Database/Seeders/index.ts +0 -2
  60. package/Database/StringExpression.ts +0 -9
  61. package/Database/Types.ts +0 -165
  62. package/Database/index.ts +0 -23
  63. package/Encryption/index.ts +0 -51
  64. package/Forms/Decorators.ts +0 -29
  65. package/Forms/Form.ts +0 -70
  66. package/Forms/FormFields.ts +0 -36
  67. package/Forms/index.ts +0 -3
  68. package/Framework/App.ts +0 -10
  69. package/Framework/Application.ts +0 -118
  70. package/Framework/Auth/Auth.ts +0 -122
  71. package/Framework/Auth/Authenticatable.ts +0 -9
  72. package/Framework/Auth/User.ts +0 -27
  73. package/Framework/Auth/index.ts +0 -29
  74. package/Framework/Config/AppConfig.ts +0 -25
  75. package/Framework/Config/AuthConfig.ts +0 -9
  76. package/Framework/Config/BaseConfig.ts +0 -9
  77. package/Framework/Config/CacheConfig.ts +0 -38
  78. package/Framework/Config/DatabaseConfig.ts +0 -21
  79. package/Framework/Config/MailConfig.ts +0 -30
  80. package/Framework/Config/index.ts +0 -6
  81. package/Framework/Middleware/AuthMiddleware.ts +0 -31
  82. package/Framework/Middleware/CorsMiddleware.ts +0 -32
  83. package/Framework/Middleware/StaticAssetsMiddleware.ts +0 -76
  84. package/Framework/Middleware/index.ts +0 -2
  85. package/Framework/Provider.ts +0 -9
  86. package/Framework/Providers/CacheProvider.ts +0 -28
  87. package/Framework/Providers/DatabaseProvider.ts +0 -36
  88. package/Framework/Providers/MailProvider.ts +0 -31
  89. package/Framework/Providers/WebsocketsProvider.ts +0 -120
  90. package/Framework/Resolvers/AuthResolver.ts +0 -23
  91. package/Framework/Resolvers/EntityResolver.ts +0 -41
  92. package/Framework/Resolvers/FormResolver.ts +0 -37
  93. package/Framework/RootDir.ts +0 -1
  94. package/Framework/index.ts +0 -8
  95. package/Frontend/Angular/index.ts +0 -24
  96. package/Frontend/Websockets/index.ts +0 -86
  97. package/Mail/MailAddress.ts +0 -4
  98. package/Mail/MailTransport.ts +0 -6
  99. package/Mail/Mailable.ts +0 -16
  100. package/Mail/Mailer.ts +0 -27
  101. package/Mail/PendingMail.ts +0 -68
  102. package/Mail/SentMessage.ts +0 -20
  103. package/Mail/Transports/MemoryTransport.ts +0 -13
  104. package/Mail/Transports/SendGridTransport.ts +0 -95
  105. package/Mail/index.ts +0 -3
  106. package/Models/Model.ts +0 -41
  107. package/Models/index.ts +0 -54
  108. package/Router/BaseController.ts +0 -7
  109. package/Router/Decorators.ts +0 -224
  110. package/Router/Guard.ts +0 -10
  111. package/Router/Http/Contracts.ts +0 -4
  112. package/Router/Http/ErrorHandler.ts +0 -45
  113. package/Router/Http/ErrorHandlerInterface.ts +0 -6
  114. package/Router/Http/Errors/HttpError.ts +0 -15
  115. package/Router/Http/Handler.ts +0 -183
  116. package/Router/Http/HttpRoute.ts +0 -110
  117. package/Router/Http/Middleware.ts +0 -7
  118. package/Router/Http/Request.ts +0 -225
  119. package/Router/Http/Response.ts +0 -35
  120. package/Router/Http/index.ts +0 -85
  121. package/Router/Metadata.ts +0 -34
  122. package/Router/Middleware.ts +0 -16
  123. package/Router/Request.ts +0 -65
  124. package/Router/Route.ts +0 -16
  125. package/Router/RouteNotFoundError.ts +0 -5
  126. package/Router/Router.ts +0 -35
  127. package/Router/Servers/index.ts +0 -6
  128. package/Router/Servers/node.ts +0 -49
  129. package/Router/Servers/uNetworking.ts +0 -151
  130. package/Router/Websockets/Handler.ts +0 -82
  131. package/Router/Websockets/Middleware.ts +0 -7
  132. package/Router/Websockets/Request.ts +0 -3
  133. package/Router/Websockets/WebsocketRoute.ts +0 -61
  134. package/Router/Websockets/index.ts +0 -57
  135. package/Router/Websockets/types.ts +0 -23
  136. package/Router/index.ts +0 -6
  137. package/Storage/File.ts +0 -30
  138. package/Storage/Image.ts +0 -19
  139. package/Storage/InvalidImage.ts +0 -3
  140. package/Storage/Storage.ts +0 -98
  141. package/Storage/index.ts +0 -4
  142. package/Storage/utils.ts +0 -18
  143. package/Support/Array.ts +0 -184
  144. package/Support/Math.ts +0 -12
  145. package/Support/Metadata.ts +0 -31
  146. package/Support/String.ts +0 -38
  147. package/Support/index.ts +0 -19
  148. package/Support/utils.ts +0 -7
  149. package/Testing/TestCase.ts +0 -193
  150. package/Validation/Rule.ts +0 -9
  151. package/Validation/RuleInterface.ts +0 -10
  152. package/Validation/Rules/Email.ts +0 -20
  153. package/Validation/Rules/FileExtension.ts +0 -21
  154. package/Validation/Rules/MaxLength.ts +0 -17
  155. package/Validation/Rules/MinLength.ts +0 -18
  156. package/Validation/Rules/Optional.ts +0 -18
  157. package/Validation/Rules/Required.ts +0 -29
  158. package/Validation/Validator.ts +0 -7
  159. package/Validation/index.ts +0 -12
  160. package/benchmark-index.js +0 -20
  161. package/benchmark.ts +0 -47
  162. package/tests/Cache/DatabaseStoreTest.ts +0 -110
  163. package/tests/Cache/FileStoreTest.ts +0 -93
  164. package/tests/Cache/MemoryStoreTest.ts +0 -92
  165. package/tests/Container/ContainerTest.ts +0 -336
  166. package/tests/Database/Drivers/MySQL/AlterTest.ts +0 -100
  167. package/tests/Database/Drivers/MySQL/CreateTest.ts +0 -39
  168. package/tests/Database/Drivers/MysqlDriverTest.ts +0 -140
  169. package/tests/Database/Drivers/SqliteDriverTest.ts +0 -126
  170. package/tests/Database/Entities/Article.ts +0 -21
  171. package/tests/Database/Entities/Profile.ts +0 -21
  172. package/tests/Database/Entities/Role.ts +0 -15
  173. package/tests/Database/Entities/User.ts +0 -35
  174. package/tests/Database/EntityRelationshipsTest.ts +0 -475
  175. package/tests/Database/EntityTest.ts +0 -202
  176. package/tests/Database/Migrations/RunnerTest.ts +0 -96
  177. package/tests/Database/Migrations/migrations/1.createUserTable.ts +0 -12
  178. package/tests/Database/Migrations/migrations/2.createArticlesTable.ts +0 -12
  179. package/tests/Database/QueryTest.ts +0 -573
  180. package/tests/Database/SchemaTest.ts +0 -32
  181. package/tests/Database/Seeders/RunnerTest.ts +0 -30
  182. package/tests/Database/Seeders/seeders/RandomSeeder.ts +0 -10
  183. package/tests/Database/utils.ts +0 -16
  184. package/tests/Forms/FormsTest.ts +0 -59
  185. package/tests/Framework/Middleware/StaticAssetsMiddlewareTest.ts +0 -129
  186. package/tests/Framework/Resolvers/EntityResolverTest.ts +0 -48
  187. package/tests/Framework/Router/RouterTest.ts +0 -33
  188. package/tests/Mail/MailerTest.ts +0 -76
  189. package/tests/Model/ModelTest.ts +0 -183
  190. package/tests/Router/HttpHandlerTest.ts +0 -72
  191. package/tests/Router/RequestTest.ts +0 -77
  192. package/tests/Router/WebSocketsHandlerTest.ts +0 -51
  193. package/tests/Storage/StorageTest.ts +0 -97
  194. package/tests/Support/ArrayTest.ts +0 -167
  195. package/tests/Support/StringTest.ts +0 -18
  196. package/tests/Validation/RulesTest.ts +0 -54
  197. package/types.d.ts +0 -8
@@ -1,96 +0,0 @@
1
- import { suite, test } from '@testdeck/mocha'
2
- import { expect } from 'chai'
3
- import { File, Storage } from '../../../Storage'
4
- import { Connection, Query, SqliteDriver } from '../../../Database'
5
- import { MigrationHistory, Migrator } from '../../../Database/Migrations'
6
- import { anything, instance, mock, when } from 'ts-mockito'
7
-
8
- @suite
9
- class RunnerTest {
10
- private runner: Migrator
11
- private migrationsPath = './tests/Database/Migrations/migrations'
12
- private migrationFiles = ['1.createUserTable.ts', '2.createArticlesTable.ts']
13
- private tableNames = ['migration_test_users', 'migration_test_articles']
14
-
15
- async before() {
16
- Query.connection = new Connection(new SqliteDriver(':memory:'))
17
- // Query.connection = new Connection(new MysqlDriver({
18
- // host: 'localhost', user: 'root', password: 'root', database: 'typetron_test'
19
- // }))
20
- this.runner = new Migrator(new Storage(), Query.connection, this.migrationsPath)
21
- }
22
-
23
- async after() {
24
- if (await Query.connection.tableExists(MigrationHistory.getTable())) {
25
- await this.runner.reset()
26
- await Query.connection.runRaw(`DROP TABLE IF EXISTS ${MigrationHistory.getTable()}`)
27
- }
28
- }
29
-
30
- @test
31
- async getFilesByPath() {
32
- const migrationFiles = await this.runner.files()
33
-
34
- expect(migrationFiles).to.have.length(2)
35
- }
36
-
37
- @test
38
- async shouldMigrate() {
39
- const migrated = await this.runner.migrate()
40
-
41
- expect(migrated).equals(true)
42
-
43
- const tables = await Query.connection.tables()
44
-
45
- expect(tables.pluck('name')).to.include.members(this.tableNames)
46
- }
47
-
48
- @test
49
- async shouldRollbackOnce() {
50
- await this.migrateInBatches()
51
-
52
- const rollback = await this.runner.rollback()
53
-
54
- expect(rollback).equals(true)
55
-
56
- const tables = await Query.connection.tables()
57
-
58
- expect(tables.pluck('name')).to.include(this.tableNames[0])
59
- expect(tables.pluck('name')).to.not.include(this.tableNames[1])
60
- }
61
-
62
- @test
63
- async shouldRollbackBySteps() {
64
- await this.migrateInBatches()
65
- const rollback = await this.runner.rollback(2)
66
-
67
- expect(rollback).equals(true)
68
-
69
- const tables = await Query.connection.tables()
70
-
71
- expect(tables.pluck('name')).to.not.include.members(this.tableNames)
72
- }
73
-
74
- @test
75
- async shouldReset() {
76
- await this.migrateInBatches()
77
- const rollback = await this.runner.reset()
78
-
79
- expect(rollback).equals(true)
80
-
81
- const tables = await Query.connection.tables()
82
-
83
- expect(tables.pluck('name')).to.not.include.members(this.tableNames)
84
- }
85
-
86
- private async migrateInBatches() {
87
- const mockStorage = mock(Storage)
88
- when(mockStorage.files(anything(), anything()))
89
- .thenReturn([new File(this.migrationFiles[0], this.migrationsPath)])
90
- .thenReturn([new File(this.migrationFiles[1], this.migrationsPath)])
91
-
92
- this.runner.storage = instance(mockStorage)
93
- await this.runner.migrate()
94
- await this.runner.migrate()
95
- }
96
- }
@@ -1,12 +0,0 @@
1
- import { Migration } from '../../../../Database/Migrations'
2
-
3
- export class CreateUserTable extends Migration {
4
-
5
- async up() {
6
- await this.connection.runRaw('CREATE TABLE migration_test_users (id INTEGER PRIMARY KEY, name TEXT, password TEXT)')
7
- }
8
-
9
- async down() {
10
- await this.connection.runRaw('DROP TABLE migration_test_users')
11
- }
12
- }
@@ -1,12 +0,0 @@
1
- import { Migration } from '../../../../Database/Migrations'
2
-
3
- export class CreateArticlesTable extends Migration {
4
-
5
- async up() {
6
- await this.connection.runRaw('CREATE TABLE migration_test_articles (id INTEGER PRIMARY KEY, title TEXT, content TEXT)')
7
- }
8
-
9
- async down() {
10
- await this.connection.runRaw('DROP TABLE migration_test_articles')
11
- }
12
- }
@@ -1,573 +0,0 @@
1
- import { expect } from 'chai'
2
- import { suite, test } from '@testdeck/mocha'
3
- import { Connection, Query } from '../../Database'
4
- import { anyOfClass, instance, mock, when } from 'ts-mockito'
5
- import { SqliteDriver } from '@Typetron/Database/Drivers'
6
- import { expectQuery, trimSQL } from '@Typetron/tests/Database/utils'
7
-
8
- @suite
9
- class QueryTest {
10
- connection: Connection
11
- private query: Query<User>
12
-
13
- before() {
14
- this.connection = mock(Connection)
15
- Query.connection = instance(this.connection)
16
- Query.connection.driver = new SqliteDriver(':memory:')
17
- when(this.connection.get(anyOfClass(Query))).thenCall((query: Query) => {
18
- return query.toSQL()
19
- })
20
- this.query = new Query()
21
- }
22
-
23
- async expect() {
24
- return expect(trimSQL(await this.query.toSQL()))
25
- }
26
-
27
- expectBindings() {
28
- return expect(this.query.getBindings())
29
- }
30
-
31
- @test
32
- async selectsEverything() {
33
- expectQuery(Query.table('users')).toEqual('SELECT * FROM users')
34
- }
35
-
36
- @test
37
- async selectSpecificColumns() {
38
- expectQuery(
39
- Query.table('users').select('name', 'email')
40
- ).toEqual(
41
- 'SELECT name, email FROM users'
42
- )
43
- }
44
-
45
- @test
46
- async addColumns() {
47
- expectQuery(
48
- Query.table('users').addSelect('name', 'email')
49
- ).toEqual(
50
- 'SELECT name, email FROM users'
51
- )
52
- }
53
-
54
- @test
55
- async selectDistinct() {
56
- expectQuery(
57
- Query.table('users').distinct().select('name', 'email')
58
- ).toEqual(
59
- 'SELECT DISTINCT name, email FROM users'
60
- )
61
- }
62
-
63
- @test
64
- async first() {
65
- when(this.connection.first(anyOfClass(Query))).thenResolve({name: 'John'})
66
- const user = await this.query.table('users').first('name');
67
-
68
- (await this.expect()).to.equal(
69
- 'SELECT name FROM users'
70
- )
71
- expect(user).to.deep.equal({name: 'John'})
72
- }
73
-
74
- @test
75
- async where() {
76
- const query = Query.table('users').where('name', '=', 'John')
77
-
78
- expectQuery(
79
- query
80
- ).toEqual(
81
- 'SELECT * FROM users WHERE name = ?'
82
- )
83
-
84
- expect(
85
- query.getBindings()
86
- ).to.deep.equal(
87
- ['John']
88
- )
89
- }
90
-
91
- @test
92
- async whereWithDefaultOperator() {
93
- const query = Query.table('users').where('name', 'John')
94
-
95
- expectQuery(
96
- query
97
- ).toEqual(
98
- 'SELECT * FROM users WHERE name = ?'
99
- )
100
- expect(
101
- query.getBindings()
102
- ).to.deep.equal(
103
- ['John']
104
- )
105
- }
106
-
107
- // @test
108
- // async whereWithObject() {
109
- // Query.table('users').where({name: 'John', age: 21});
110
- //
111
- // (await this.expectSql()).to.equal('SELECT * FROM users WHERE name = ? AND age = ?');
112
- // this.expectBindings().to.deep.equal(['John', 21]);
113
- // }
114
-
115
- // @test
116
- // async whereWithArray() {
117
- // Query.table('users').where([
118
- // ['name', '=', 'John'],
119
- // ['age', '=', 21]
120
- // ]);
121
- //
122
- // (await this.expectSql()).to.equal('SELECT * FROM users WHERE name = ? AND age = ?');
123
- // this.expectBindings().to.deep.equal(['John', 21]);
124
- // }
125
-
126
- @test
127
- async whereOrOperator() {
128
- this.query.table('users').where('name', 'John').orWhere('age', 21);
129
-
130
- (await this.expect()).to.equal(
131
- 'SELECT * FROM users WHERE name = ? OR age = ?'
132
- )
133
- this.expectBindings().to.deep.equal(['John', 21])
134
- }
135
-
136
- @test
137
- async whereBetween() {
138
- this.query.table('users').whereBetween('age', [18, 25]);
139
-
140
- (await this.expect()).to.equal(
141
- 'SELECT * FROM users WHERE age BETWEEN ? AND ?'
142
- )
143
- this.expectBindings().to.deep.equal([18, 25])
144
- }
145
-
146
- @test
147
- async whereNotBetween() {
148
- this.query.table('users').whereNotBetween('age', [18, 25]);
149
-
150
- (await this.expect()).to.equal(
151
- 'SELECT * FROM users WHERE age NOT BETWEEN ? AND ?'
152
- )
153
- this.expectBindings().to.deep.equal([18, 25])
154
- }
155
-
156
- @test
157
- async orWhereBetween() {
158
- this.query.table('users').where('name', 'John').orWhereBetween('age', [18, 25]);
159
-
160
- (await this.expect()).to.equal(
161
- 'SELECT * FROM users WHERE name = ? OR age BETWEEN ? AND ?'
162
- )
163
- this.expectBindings().to.deep.equal(['John', 18, 25])
164
- }
165
-
166
- @test
167
- async orWhereNotBetween() {
168
- this.query.table('users').where('name', 'John').orWhereNotBetween('age', [18, 25]);
169
-
170
- (await this.expect()).to.equal(
171
- 'SELECT * FROM users WHERE name = ? OR age NOT BETWEEN ? AND ?'
172
- )
173
- this.expectBindings().to.deep.equal(['John', 18, 25])
174
- }
175
-
176
- @test
177
- async whereIn() {
178
- this.query.table('users').whereIn('age', [18, 25]);
179
-
180
- (await this.expect()).to.equal(
181
- 'SELECT * FROM users WHERE age IN (?, ?)'
182
- )
183
- this.expectBindings().to.deep.equal([18, 25])
184
- }
185
-
186
- @test
187
- async whereNotIn() {
188
- this.query.table('users').whereNotIn('age', [18, 25]);
189
-
190
- (await this.expect()).to.equal(
191
- 'SELECT * FROM users WHERE age NOT IN (?, ?)'
192
- )
193
- this.expectBindings().to.deep.equal([18, 25])
194
- }
195
-
196
- @test
197
- async orWhereIn() {
198
- this.query.table('users').where('name', 'John').orWhereIn('age', [18, 25]);
199
-
200
- (await this.expect()).to.equal(
201
- 'SELECT * FROM users WHERE name = ? OR age IN (?, ?)'
202
- )
203
- this.expectBindings().to.deep.equal(['John', 18, 25])
204
- }
205
-
206
- @test
207
- async orWhereNotIn() {
208
- this.query.table('users').where('name', 'John').orWhereNotIn('age', [18, 25]);
209
-
210
- (await this.expect()).to.equal(
211
- 'SELECT * FROM users WHERE name = ? OR age NOT IN (?, ?)'
212
- )
213
- this.expectBindings().to.deep.equal(['John', 18, 25])
214
- }
215
-
216
- @test
217
- async whereNull() {
218
- this.query.table('users').whereNull('age');
219
-
220
- (await this.expect()).to.equal(
221
- 'SELECT * FROM users WHERE age IS NULL'
222
- )
223
- this.expectBindings().to.deep.equal([])
224
- }
225
-
226
- @test
227
- async andWhereNull() {
228
- this.query.table('users').andWhereNull('age');
229
-
230
- (await this.expect()).to.equal(
231
- 'SELECT * FROM users WHERE age IS NULL'
232
- )
233
- this.expectBindings().to.deep.equal([])
234
- }
235
-
236
- @test
237
- async whereNotNull() {
238
- this.query.table('users').whereNotNull('age');
239
-
240
- (await this.expect()).to.equal(
241
- 'SELECT * FROM users WHERE age IS NOT NULL'
242
- )
243
- this.expectBindings().to.deep.equal([])
244
- }
245
-
246
- @test
247
- async andWhereNotNull() {
248
- this.query.table('users').andWhereNotNull('age');
249
-
250
- (await this.expect()).to.equal(
251
- 'SELECT * FROM users WHERE age IS NOT NULL'
252
- )
253
- this.expectBindings().to.deep.equal([])
254
- }
255
-
256
- @test
257
- async orWhereNull() {
258
- this.query.table('users').where('name', 'John').orWhereNull('age');
259
-
260
- (await this.expect()).to.equal(
261
- 'SELECT * FROM users WHERE name = ? OR age IS NULL'
262
- )
263
- this.expectBindings().to.deep.equal(['John'])
264
- }
265
-
266
- @test
267
- async orWhereNotNull() {
268
- this.query.table('users').where('name', 'John').orWhereNotNull('age');
269
-
270
- (await this.expect()).to.equal(
271
- 'SELECT * FROM users WHERE name = ? OR age IS NOT NULL'
272
- )
273
- this.expectBindings().to.deep.equal(['John'])
274
- }
275
-
276
- @test
277
- async orWhereLike() {
278
- this.query.table('users').where('age', 18).orWhereLike('name', '%John');
279
-
280
- (await this.expect()).to.equal(
281
- 'SELECT * FROM users WHERE age = ? OR name LIKE ?'
282
- )
283
- this.expectBindings().to.deep.equal([18, '%John'])
284
- }
285
-
286
- @test
287
- async orWhereNotLike() {
288
- this.query.table('users').where('age', 18).orWhereNotLike('name', '%John');
289
-
290
- (await this.expect()).to.equal(
291
- 'SELECT * FROM users WHERE age = ? OR name NOT LIKE ?'
292
- )
293
- this.expectBindings().to.deep.equal([18, '%John'])
294
- }
295
-
296
- @test
297
- async andWhereIn() {
298
- this.query.table('users').where('age', 18).andWhereIn('name', ['John', 'Doe']);
299
-
300
- (await this.expect()).to.equal(
301
- 'SELECT * FROM users WHERE age = ? AND name IN (?, ?)'
302
- )
303
- this.expectBindings().to.deep.equal([18, 'John', 'Doe'])
304
- }
305
-
306
- @test
307
- async andWhereNotIn() {
308
- this.query.table('users').where('age', 18).andWhereNotIn('name', ['John', 'Doe']);
309
-
310
- (await this.expect()).to.equal(
311
- 'SELECT * FROM users WHERE age = ? AND name NOT IN (?, ?)'
312
- )
313
- this.expectBindings().to.deep.equal([18, 'John', 'Doe'])
314
- }
315
-
316
- @test
317
- async whereLike() {
318
- this.query.table('users').whereLike('name', '%John');
319
-
320
- (await this.expect()).to.equal(
321
- 'SELECT * FROM users WHERE name LIKE ?'
322
- )
323
- this.expectBindings().to.deep.equal(['%John'])
324
- }
325
-
326
- @test
327
- async andWhere() {
328
- this.query.table('users').where('name', 'John').andWhere('age', 18);
329
-
330
- (await this.expect()).to.equal(
331
- 'SELECT * FROM users WHERE name = ? AND age = ?'
332
- )
333
- this.expectBindings().to.deep.equal(['John', 18])
334
- }
335
-
336
- // @test
337
- // async whereParameterGrouping() {
338
- // this.query.table('users')
339
- // .where('name', 'John')
340
- // .where(query => query.where('age', 21).orWhere('role', 'Admin'));
341
- //
342
- // (await this.expectSql()).to.equal('SELECT * FROM users WHERE name = ? and (age = ? or role = ?)');
343
- // this.expectBindings().to.deep.equal(['john', 21, 'Admin']);
344
- // }
345
-
346
- @test
347
- async orderBys() {
348
- this.query.table('users').orderBy('age');
349
- (await this.expect()).to.equal(
350
- 'SELECT * FROM users ORDER BY age DESC'
351
- )
352
-
353
- this.query.table('users').orderBy('age', 'ASC');
354
- (await this.expect()).to.equal(
355
- 'SELECT * FROM users ORDER BY age ASC'
356
- )
357
-
358
- this.query.table('users').orderBy([['age', 'DESC'], ['email', 'ASC']]);
359
- (await this.expect()).to.equal(
360
- 'SELECT * FROM users ORDER BY age DESC, email ASC'
361
- )
362
- }
363
-
364
- @test
365
- async groupBy() {
366
- this.query.table('users').groupBy('name');
367
- (await this.expect()).to.equal(
368
- 'SELECT * FROM users GROUP BY name'
369
- )
370
-
371
- this.query.table('users').groupBy('city', 'country');
372
- (await this.expect()).to.equal(
373
- 'SELECT * FROM users GROUP BY city, country'
374
- )
375
- }
376
-
377
- @test
378
- async aggregateSelectCount() {
379
- const query = await this.query.table('users').selectCount().get() as unknown as string
380
- expectQuery(query).toEqual('SELECT COUNT(*) as aggregate FROM users')
381
- }
382
-
383
- @test
384
- async aggregateCount() {
385
- when(this.connection.first(anyOfClass(Query))).thenCall((query: Query) => {
386
- return {aggregate: trimSQL(query.toSQL())}
387
- })
388
-
389
- expect(await this.query.table('users').count()).to.equal('SELECT COUNT(*) as aggregate FROM users')
390
- }
391
-
392
- @test
393
- async aggregateMax() {
394
- const query = await this.query.table('users').max('age') as unknown as string
395
- expectQuery(query).toEqual('SELECT MAX(age) as aggregate FROM users')
396
- }
397
-
398
- @test
399
- async limit() {
400
- const query = await this.query.table('users').limit(10, 20).get() as unknown as string
401
- expectQuery(
402
- query
403
- ).toEqual(
404
- 'SELECT * FROM users LIMIT 10, 20'
405
- )
406
- }
407
-
408
- //
409
- // @test
410
- // async aggregateMax() {
411
- // this.query.table('users').max('age');
412
- // (await this.expectSql()).to.equal('SELECT MAX(age) as aggregate FROM users');
413
- // }
414
-
415
- @test
416
- async defaultJoin() {
417
- this.query.table('users').join('pets', 'pets.user_id', '=', 'users.id');
418
- (await this.expect()).to.equal(
419
- 'SELECT * FROM users INNER JOIN pets ON pets.user_id = users.id'
420
- )
421
-
422
- // this.new.query.table('users')
423
- // .join('pets', 'pets.user_id', '=', 'users.id')
424
- // .leftJoin('pet_types', 'pet_types.id', '=', 'pets.type_id');
425
- // (await this.expectSql()).to
426
- // .equal('SELECT * FROM users INNER JOIN pets ON pets.user_id = users.id LEFT JOIN pet_types ON pet_types.id = pets.type_id');
427
- }
428
-
429
- @test
430
- async innerJoin() {
431
- this.query.table('users').innerJoin('pets', 'pets.user_id', '=', 'users.id');
432
- (await this.expect()).to.equal(
433
- 'SELECT * FROM users INNER JOIN pets ON pets.user_id = users.id'
434
- )
435
- }
436
-
437
- @test
438
- async leftJoin() {
439
- this.query.table('users').leftJoin('pets', 'pets.user_id', '=', 'users.id');
440
- (await this.expect()).to.equal(
441
- 'SELECT * FROM users LEFT JOIN pets ON pets.user_id = users.id'
442
- )
443
- }
444
-
445
- @test
446
- async rightJoin() {
447
- this.query.table('users').rightJoin('pets', 'pets.user_id', '=', 'users.id');
448
- (await this.expect()).to.equal(
449
- 'SELECT * FROM users RIGHT JOIN pets ON pets.user_id = users.id'
450
- )
451
- }
452
-
453
- @test
454
- async insertOneRow() {
455
- this.query.table('users').insert({
456
- name: 'John',
457
- email: 'john@example.com'
458
- });
459
- (await this.expect()).to.equal(
460
- 'INSERT INTO users (name, email) VALUES (?, ?)'
461
- )
462
- this.expectBindings().to.deep.equal(['John', 'john@example.com'])
463
- }
464
-
465
- @test
466
- async insertManyRow() {
467
- this.query.table('users').insert([
468
- {
469
- name: 'John',
470
- email: 'john@example.com'
471
- },
472
- {
473
- name: 'Chris',
474
- email: 'chris@example.com'
475
- }
476
- ]);
477
- (await this.expect()).to.equal(
478
- 'INSERT INTO users (name, email) VALUES (?, ?), (?, ?)'
479
- )
480
- this.expectBindings().to.deep.equal(['John', 'john@example.com', 'Chris', 'chris@example.com'])
481
- }
482
-
483
- @test
484
- async delete() {
485
- this.query.table('users').delete();
486
-
487
- (await this.expect()).to.equal(
488
- 'DELETE FROM users'
489
- )
490
- }
491
-
492
- @test
493
- async deletesWithCondition() {
494
- this.query.table('users').where('name', 'John').delete();
495
-
496
- (await this.expect()).to.equal(
497
- 'DELETE FROM users WHERE name = ?'
498
- )
499
- this.expectBindings().to.deep.equal(['John'])
500
- }
501
-
502
- @test
503
- async update() {
504
- this.query.table('users').update('name', 'John');
505
-
506
- (await this.expect()).to.equal(
507
- 'UPDATE users SET name = ?'
508
- )
509
- this.expectBindings().to.deep.equal(['John'])
510
- }
511
-
512
- @test
513
- async updateMultipleColumns() {
514
- this.query.table('users').update({
515
- name: 'John',
516
- age: 21,
517
- });
518
-
519
- (await this.expect()).to.equal(
520
- 'UPDATE users SET name = ?, age = ?'
521
- )
522
- this.expectBindings().to.deep.equal(['John', 21])
523
- }
524
-
525
- @test
526
- async updateWithCondition() {
527
- this.query.table('users').where('name', 'John').update('name', 'Doe');
528
- (await this.expect()).to.equal(
529
- 'UPDATE users SET name = ? WHERE name = ?'
530
- )
531
- this.expectBindings().to.deep.equal(['Doe', 'John'])
532
- }
533
-
534
- @test
535
- async subSelectWhereWithFunction() {
536
- const query = Query.table('users').where('id', q => {
537
- q.select('userId').from('roles').where('id', 1)
538
- })
539
- expect(trimSQL(query.toSQL())).to.equal('SELECT * FROM users WHERE id = (SELECT userId FROM roles WHERE id = ?)')
540
- expect(query.getBindings()).to.deep.equal([1])
541
- }
542
-
543
- @test
544
- async subSelectWhereWithDirectQuery() {
545
- const query = Query.table('users').where('id', new Query().select('userId').from('roles').where('id', 1))
546
- expect(trimSQL(query.toSQL())).to.equal('SELECT * FROM users WHERE id = (SELECT userId FROM roles WHERE id = ?)')
547
- expect(query.getBindings()).to.deep.equal([1])
548
- }
549
-
550
- @test
551
- async subSelectWhereInWithFunction() {
552
- const query = Query.table('users').whereIn('id', q => {
553
- q.select('userId').from('roles').where('id', 1)
554
- })
555
- expect(trimSQL(query.toSQL())).to.equal('SELECT * FROM users WHERE id IN (SELECT userId FROM roles WHERE id = ?)')
556
- expect(query.getBindings()).to.deep.equal([1])
557
- }
558
-
559
- @test
560
- async subSelectWhereInWithDirectQuery() {
561
- const query = Query.table('users').whereIn('id', new Query().select('userId').from('roles').where('id', 1))
562
- expect(trimSQL(query.toSQL())).to.equal('SELECT * FROM users WHERE id IN (SELECT userId FROM roles WHERE id = ?)')
563
- expect(query.getBindings()).to.deep.equal([1])
564
- }
565
- }
566
-
567
- interface User {
568
- id: number;
569
- age: number;
570
- email: string;
571
- name: string;
572
- dateOfBirth: Date;
573
- }