Skip to content

Commit

Permalink
Merge pull request #1094 from ttemple06/table-rows-clear
Browse files Browse the repository at this point in the history
Add table.rows.clear() method for chunking table row updates
  • Loading branch information
dhensby committed Nov 22, 2021
2 parents 275e6d7 + e986454 commit 8c85f77
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
v8.0.0 (2021-??-??)
-------------------
[new] Add table.rows.clear() method to allow for chunking updates ([#1094](https://github.com/tediousjs/node-mssql/pull/1094))
[change] msnodesqlv8 driver detects os platform and attempts to pick correct connections string for it ((#1318)[https://github.com/tediousjs/node-mssql/pull/1318])
[change] Updated to latest Tedious 14 ((#1312)[https://github.com/tediousjs/node-mssql/pull/1312])
[change] Errors for bad bulk load parameters have slightly different error messages ((#1318)[https://github.com/tediousjs/node-mssql/pull/1318])
Expand Down Expand Up @@ -255,7 +256,7 @@ v4.0.4 (2017-04-25)

v4.0.3 (2017-04-25)
-------------------
[fix] Fixed broken CLI & debugging
[fix] Fixed broken CLI & debugging

v4.0.2 (2017-04-19)
-------------------
Expand All @@ -276,7 +277,7 @@ v4.0.0 (2017-04-01)
[change] Removed verbose and debug mode
[change] Removed 'driver' from options
[change] Removed Transaction and Prepared Statement queues
[change] Removed 'multiple' directive
[change] Removed 'multiple' directive
[change] Connection renamed to ConnectionPool
[change] Updated to latest Tedious 2.0.0

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,20 @@ request.execute('MyCustomStoredProcedure', (err, result) => {

**TIP**: You can also create Table variable from any recordset with `recordset.toTable()`. You can optionally specify table type name in the first argument.

You can clear the table rows for easier batching by using `table.rows.clear()`

```js
const tvp = new sql.Table() // You can optionally specify table type name in the first argument.

// Columns must correspond with type we have created in database.
tvp.columns.add('a', sql.VarChar(50))
tvp.columns.add('b', sql.Int)

// Add rows
tvp.rows.add('hello tvp', 777) // Values are in same order as columns.
tvp.rows.clear()
```

## Response Schema

An object returned from a `sucessful` basic query would look like the following.
Expand Down
7 changes: 7 additions & 0 deletions lib/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function Table (name) {
}
}
)

Object.defineProperty(this.rows, 'clear', {
value () {
return this.splice(0, this.length)
}
}
)
}

/*
Expand Down
3 changes: 3 additions & 0 deletions test/common/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ describe('Unit', () => {
assert.deepStrictEqual(t.rows[3], [12, 'XCXCDCDSCDSC'])
assert.strictEqual(t.temporary, false)

t.rows.clear()
assert.strictEqual(t.rows.length, 0)

t = new sql.Table('schm.MyTable')

assert.strictEqual(t.name, 'MyTable')
Expand Down

0 comments on commit 8c85f77

Please sign in to comment.