You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+41-41Lines changed: 41 additions & 41 deletions
Original file line number
Diff line number
Diff line change
@@ -70,15 +70,15 @@ Use the node package manager [npm](https://www.npmjs.com/package/fluent-mysql) t
70
70
npm install fluent-mysql
71
71
```
72
72
73
-
```node
73
+
```js
74
74
constDB=require('fluent-mysql');
75
75
```
76
76
77
77
## Connection to Database
78
78
The parameters are the same with [mysql](https://www.npmjs.com/package/mysql) library. You can list all options from [here](https://www.npmjs.com/package/mysql#connection-options)
79
79
80
80
81
-
```node
81
+
```js
82
82
constDB=require('fluent-mysql');
83
83
84
84
let connection =DB.connect({
@@ -105,7 +105,7 @@ connection.then(result => {
105
105
106
106
It is necessary to specify `table` in all queries except for writing your own query with `query` method.
107
107
108
-
```node
108
+
```js
109
109
// Get all records from users table
110
110
let users =DB.table('users').get();
111
111
@@ -118,7 +118,7 @@ users.then( results => {
118
118
119
119
Using the `select` method, you can specify a custom select clause for the query.
120
120
121
-
```node
121
+
```js
122
122
let users =DB.table('users').select('name', 'phone', 'age').get();
123
123
124
124
users.then( results=> {
@@ -129,7 +129,7 @@ users.then( results => {
129
129
130
130
You can also use the distinct method to force the query to return distinct results.
131
131
132
-
```node
132
+
```js
133
133
let users =DB.table('users').select('name').distinct().get();
134
134
135
135
users.then( results=> {
@@ -147,7 +147,7 @@ users.then( results => {
147
147
148
148
`get` must be the last method in methods chain.
149
149
150
-
```node
150
+
```js
151
151
let users =DB.table('users').get();
152
152
153
153
users.then( results=> {
@@ -158,7 +158,7 @@ users.then( results => {
158
158
### first()
159
159
You can get only the first row from all results.
160
160
161
-
```node
161
+
```js
162
162
let users =DB.table('users').first();
163
163
164
164
users.then( result=> {
@@ -170,7 +170,7 @@ users.then( result => {
170
170
To retrieve a single row by its id column value, use the `find` method:
171
171
172
172
173
-
```node
173
+
```js
174
174
let users =DB.table('users').find(10);
175
175
176
176
users.then( result=> {
@@ -181,7 +181,7 @@ users.then( result => {
181
181
### query()
182
182
183
183
You can also write your own query with `query` method.
184
-
```node
184
+
```js
185
185
let users =DB.query(`SELECT * FROM users WHERE name = "John"`).get();
186
186
187
187
users.then( results=> {
@@ -194,7 +194,7 @@ users.then( results => {
194
194
### where()
195
195
196
196
197
-
```node
197
+
```js
198
198
let users =DB.table('users').where('userName', '=', 'John' ).get();
199
199
200
200
users.then( results=> {
@@ -205,7 +205,7 @@ users.then( results => {
205
205
### orWhere()
206
206
207
207
208
-
```node
208
+
```js
209
209
let users =DB.table('users').where('userName', '=', 'John' ).orWhere('age', '>', 20 ).get();
210
210
211
211
users.then( results=> {
@@ -216,7 +216,7 @@ users.then( results => {
216
216
### whereBetween()
217
217
218
218
219
-
```node
219
+
```js
220
220
// Get users whose ages between 20 and 30
221
221
let users =DB.table('users').whereBetween('age', 20, 40 ).get();
222
222
@@ -228,7 +228,7 @@ users.then( results => {
228
228
### orWhereBetween()
229
229
230
230
231
-
```node
231
+
```js
232
232
let users =DB.table('users').where('name', '=', 'John' ).orWhereBetween('age', 30, 40 ).get();
233
233
234
234
users.then( results=> {
@@ -239,7 +239,7 @@ users.then( results => {
239
239
### whereNotBetween()
240
240
241
241
242
-
```node
242
+
```js
243
243
let users =DB.table('users').whereNotBetween('age', 50, 60 ).get();
244
244
245
245
users.then( results=> {
@@ -250,7 +250,7 @@ users.then( results => {
250
250
### orWhereNotBetween()
251
251
252
252
253
-
```node
253
+
```js
254
254
let users =DB.table('users').whereBetween('salary', 1000, 2000 ).orWhereNotBetween('age', 50, 60 ).get();
255
255
256
256
users.then( results=> {
@@ -261,7 +261,7 @@ users.then( results => {
261
261
### whereIn()
262
262
263
263
264
-
```node
264
+
```js
265
265
let users =DB.table('users').whereIn('age', [25,35,45] ).get();
266
266
267
267
users.then( results=> {
@@ -273,7 +273,7 @@ users.then( results => {
273
273
### orWhereIn()
274
274
275
275
276
-
```node
276
+
```js
277
277
let users =DB.table('users').where('userName', '=', 'John' ).orWhereIn('age', [25,35,45] ).get();
278
278
279
279
users.then( results=> {
@@ -285,7 +285,7 @@ users.then( results => {
285
285
### whereNotIn()
286
286
287
287
288
-
```node
288
+
```js
289
289
let users =DB.table('users').whereNotIn('age', [25,35,45] ).get();
290
290
291
291
users.then( results=> {
@@ -297,7 +297,7 @@ users.then( results => {
297
297
### orWhereNotIn()
298
298
299
299
300
-
```node
300
+
```js
301
301
let users =DB.table('users').where('userName', '=', 'John' ).orWhereNotIn('age', [20,30,40] ).get();
302
302
303
303
users.then( results=> {
@@ -309,7 +309,7 @@ users.then( results => {
309
309
### whereNull()
310
310
311
311
312
-
```node
312
+
```js
313
313
let users =DB.table('users').whereNull('phone').get();
314
314
315
315
users.then( results=> {
@@ -321,7 +321,7 @@ users.then( results => {
321
321
### orWhereNull()
322
322
323
323
324
-
```node
324
+
```js
325
325
let users =DB.table('users').whereNull('phone').orWhereNull('email').get();
326
326
327
327
users.then( results=> {
@@ -333,7 +333,7 @@ users.then( results => {
333
333
### whereNotNull()
334
334
335
335
336
-
```node
336
+
```js
337
337
let users =DB.table('users').whereNotNull('phone' ).get();
338
338
339
339
users.then( results=> {
@@ -344,7 +344,7 @@ users.then( results => {
344
344
### orWhereNotNull()
345
345
346
346
347
-
```node
347
+
```js
348
348
let users =DB.table('users').where('age', '>', 25 ).orWhereNotNull('email').get();
349
349
350
350
users.then( results=> {
@@ -358,7 +358,7 @@ users.then( results => {
358
358
The `orderBy` method allows you to sort the result of the query by a given column. The first argument to the `orderBy` method should be the column you wish to sort by, while the second argument controls the direction of the sort and may be either `asc` or `desc`.
359
359
360
360
361
-
```node
361
+
```js
362
362
let users =DB.table('users').orderBy('name', 'ASC').get();
363
363
364
364
users.then( results=> {
@@ -369,7 +369,7 @@ users.then( results => {
369
369
### limit()
370
370
To limit the number of results returned from the query, you may use the `limit` method.
371
371
372
-
```node
372
+
```js
373
373
let users =DB.table('users').limit(20).get();
374
374
375
375
users.then( results=> {
@@ -380,7 +380,7 @@ users.then( results => {
380
380
### offset()
381
381
To skip a given number of results in the query, you may use the `offset` method.
382
382
383
-
```node
383
+
```js
384
384
let users =DB.table('users').limit(20).offset(10).get();
385
385
386
386
users.then( results=> {
@@ -392,7 +392,7 @@ users.then( results => {
392
392
393
393
The `groupBy` and `having` methods may be used to group the query results.
394
394
395
-
```node
395
+
```js
396
396
let authorBooks =DB.table('books')
397
397
.select('author', 'COUNT(bookID) AS totalBook')
398
398
.groupBy('author')
@@ -412,7 +412,7 @@ Currently **fluent-mysql** supports only inner join.
412
412
413
413
The **fluent-mysql** may also be used to write join statements. The first argument passed to the join method is the name of the table you need to join to, while the remaining arguments specify the column constraints for the join. You can even join to multiple tables in a single query.
0 commit comments