Skip to content

Commit

Permalink
Add count methods
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcamilleri committed Mar 16, 2019
1 parent a94bc5c commit afe0b7b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gabra-api",
"version": "2.9.2",
"version": "2.10.0",
"description": "Ġabra: an open lexicon for Maltese",
"author": "John J. Camilleri <[email protected]> (http:https://johnjcamilleri.com/)",
"license": "MIT",
Expand Down
12 changes: 11 additions & 1 deletion public/markdown/api.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="page-header">
<h1>Ġabra API v2.9.1 <small>Updated 2018-09-01</small></h1>
<h1>Ġabra API v2.10.0 <small>Updated 2019-03-16</small></h1>
</div>

<div class="well">
Expand Down Expand Up @@ -180,3 +180,13 @@ You can get English & Maltese names for all the field names and values:
| Argument | Description | Example |
|:---------|:------------|:-------------------------|
| `lang` | Language | `eng` (default) or `mlt` |

### Counts <small>Since v2.10.0</small>

Get counts of all entities in database. These commands take no parameters.

> [/lexemes/count](#{baseURL}/lexemes/count)
> [/wordforms/count](#{baseURL}/wordforms/count)
> [/roots/count](#{baseURL}/roots/count)
11 changes: 11 additions & 0 deletions routes/lexemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,17 @@ router.get('/lemmatise', function (req, res) {
})
})

/*
* GET count
*/
router.get('/count', function (req, res) {
var db = req.db
var coll = db.get('lexemes')
coll.count({}, function (err, result) {
res.json(result)
})
})

// -- Private helper methods ------------------------------------------------

function boolItem (obj, key, def) {
Expand Down
12 changes: 12 additions & 0 deletions routes/roots.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ router.get('/lexemes/:radicals/:variant?', function (req, res, next) {
})
})

/*
* GET count
*/
router.get('/count', function (req, res) {
var db = req.db
var coll = db.get('roots')
coll.count({}, function (err, result) {
res.json(result)
})
})


// -- Private methods -------------------------------------------------------

var getQuery = function (req) {
Expand Down
11 changes: 11 additions & 0 deletions routes/wordforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ router.post('/replace/:lexeme_id',
})
})

/*
* GET count
*/
router.get('/count', function (req, res) {
var db = req.db
var coll = db.get('wordforms')
coll.count({}, function (err, result) {
res.json(result)
})
})

// -- CRUD Methods ----------------------------------------------------------

/* Create = POST */
Expand Down

0 comments on commit afe0b7b

Please sign in to comment.