mevn-orm 2.2.6 → 2.2.7

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/lib/model.js CHANGED
@@ -53,6 +53,25 @@ class Model {
53
53
  }
54
54
  }
55
55
 
56
+ /**
57
+ * Update a model
58
+ * @param {*} properties
59
+ * @returns this
60
+ */
61
+ async update(properties) {
62
+ try {
63
+ const id = await DB(this.table)
64
+ .where({ id: this.id })
65
+ .update(properties)
66
+ const fields = await DB(this.table).where({ id }).first()
67
+ // console.log(fields)
68
+ return this.stripColumns(new this.constructor(fields))
69
+ } catch (error) {
70
+ console.log(error)
71
+ }
72
+ }
73
+
74
+
56
75
  /**
57
76
  * Update a model
58
77
  * @param {*} properties
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mevn-orm",
3
- "version": "2.2.6",
3
+ "version": "2.2.7",
4
4
  "description": "simple ORM for express js",
5
5
  "type": "commonjs",
6
6
  "scripts": {
@@ -42,6 +42,16 @@ describe('#Model tests', () => {
42
42
  expect(farmer.id).to.be.a('number')
43
43
  })
44
44
 
45
+ it('#Update a model with a new instance', async () => {
46
+ const farmer = await Farmer.find(1)
47
+ await farmer.update({
48
+ name: 'new name',
49
+ email: faker.internet.email(),
50
+ password: faker.internet.password()
51
+ })
52
+ expect(farmer).to.an('Object')
53
+ })
54
+
45
55
  it('#Has one relationship', async () => {
46
56
  const farmer = new Farmer({
47
57
  name: faker.name.findName(),