neopg 0.0.1 → 1.0.0

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.
package/test/test-db.js CHANGED
@@ -66,16 +66,6 @@ const User = {
66
66
  type: dataTypes.STRING(240)
67
67
  },
68
68
 
69
- //通过触摸手势或轨迹生成的密码
70
- touchpass: {
71
- type: dataTypes.STRING(300)
72
- },
73
-
74
- is_external: {
75
- type: dataTypes.SMALLINT,
76
- default: 0
77
- },
78
-
79
69
  /**
80
70
  * @type {column}
81
71
  */
@@ -143,8 +133,7 @@ const User = {
143
133
  //唯一索引
144
134
  unique: [
145
135
  'username',
146
- 'email',
147
- 'mobile'
136
+ 'email'
148
137
  ]
149
138
  }
150
139
 
@@ -155,23 +144,74 @@ db.add(User);
155
144
  await db.sync({force: true, debug: true})
156
145
  // 插入
157
146
 
158
- await db.model('User').insert({username: 'Neo', level: Math.floor((Math.random() * 101))})
147
+ await db.model('User').where('1=1').delete()
148
+
149
+ try {
150
+ console.log(
151
+ await db.model('User')
152
+ .returning(['id', 'username', 'level', 'create_time'])
153
+ .insert([
154
+ {
155
+ username: 'Neo',
156
+ email: '123@w.com',
157
+ level: Math.floor((Math.random() * 105))
158
+ },
159
+ {
160
+ username: 'PG',
161
+ email: '1234@w.com',
162
+ level: Math.floor((Math.random() * 100))
163
+ }
164
+ ])
165
+ )
166
+ } catch(err) {
167
+ console.error('\x1b[7;5m随机测试:让level超过99,validate验证失败\x1b[0m')
168
+ }
159
169
 
160
170
  // 事务
161
171
  await db.transaction(async tx => {
162
172
  let data = {
163
- level: Math.floor(Math.random() * 101),
164
- info: `age=${Math.floor(Math.random() * 10 + 20)}`
173
+ level: Math.floor(Math.random() * 100),
174
+ info: `age=${Math.floor(Math.random() * 10 + 20)};delete from users;`
165
175
  }
166
176
 
167
177
  console.log('update', data)
168
- await tx.model('User').where(tx.sql`level > 10`).update(data)
178
+
179
+ let result = await tx.model('User').where(tx.sql`level > 10`).returning('*').update(data)
180
+ console.log(result)
181
+
182
+ console.log(
183
+ 'test avg',
184
+ await tx.model('User').avg('level')
185
+ )
186
+
187
+ console.log(
188
+ 'test max',
189
+ await tx.model('User').max('level')
190
+ )
191
+
192
+ console.log(
193
+ 'test min',
194
+ await tx.model('User').min('username')
195
+ )
196
+
197
+ let n = Math.floor(Math.random() * 10)
198
+
199
+ if (n > 7) {
200
+ console.error('\x1b[7;5m随机测试:将会让事物执行失败\x1b[0m')
201
+ await tx.model('User').insert({username: 'Neo'})
202
+ }
203
+
204
+ console.log('test count',
205
+ await tx.model('User').where('level', '<', 10).count()
206
+ )
169
207
 
170
208
  // 嵌套
171
209
  /* await tx.transaction(async subTx => {
172
210
  await subTx.table('logs').insert({ msg: 'log' });
173
211
  }); */
174
- });
212
+ }).catch(err => {
213
+ console.error(err)
214
+ })
175
215
 
176
216
  db.close()
177
217
  })();