|
13 | 13 | const assert = require('assert'); |
14 | 14 | const path = require('path'); |
15 | 15 |
|
16 | | -const { Sequelize, DataTypes } = require('sequelize'); |
| 16 | +const { Sequelize, DataTypes, Op } = require('sequelize'); |
17 | 17 |
|
18 | 18 | // To use the URI syntax, we need an explcit username and password. |
19 | 19 | // But the second constructor works with peer authentication. |
@@ -96,17 +96,30 @@ await IntegerNames.create({value: 5, name: 'five'}); |
96 | 96 | // 3 | 5 | five | 2021-03-19 19:12:08.437+00 | 2021-03-19 19:12:08.437+00 |
97 | 97 | // (3 rows) |
98 | 98 |
|
99 | | -const integerNames = await IntegerNames.findAll({ |
| 99 | +let integerNames = await IntegerNames.findAll({ |
100 | 100 | where: { |
101 | 101 | value: 2 |
102 | 102 | } |
103 | 103 | }); |
104 | 104 | assert.strictEqual(integerNames[0].name, 'two'); |
| 105 | +assert.strictEqual(integerNames.length, 1); |
| 106 | + |
| 107 | +// SELECT and destroy: https://stackoverflow.com/questions/8402597/sequelize-js-delete-query |
| 108 | +await IntegerNames.destroy({ |
| 109 | + where: { |
| 110 | + value: { [Op.gt]: 2 }, |
| 111 | + }, |
| 112 | + limit: 1, |
| 113 | +}); |
| 114 | +integerNames = await IntegerNames.findAll({order: [['value', 'ASC']]}) |
| 115 | +assert.strictEqual(integerNames[0].name, 'two'); |
| 116 | +assert.strictEqual(integerNames[1].name, 'five'); |
| 117 | +assert.strictEqual(integerNames.length, 2); |
105 | 118 |
|
106 | 119 | // Truncate all tables. |
107 | 120 | // https://stackoverflow.com/questions/47816162/wipe-all-tables-in-a-schema-sequelize-nodejs/66985334#66985334 |
108 | 121 | await sequelize.truncate(); |
109 | | -assert.strictEqual((await IntegerNames.findAll()).length, 0); |
| 122 | +assert.strictEqual(await IntegerNames.count(), 0); |
110 | 123 |
|
111 | 124 | // Datetime. Automatically converts to/from date objects. |
112 | 125 | const Dates = sequelize.define('Dates', { |
|
0 commit comments