dirigeants / klasa-pieces

MIT License
44 stars 55 forks source link

Count() For RethinkDB #199

Closed Skillz4Killz closed 5 years ago

Skillz4Killz commented 5 years ago

This PR adds in the functionality to get the amount of documents in a table for the RDB provider.

this.client.providers.default.count('TABLENAME')

Use Cases:

const table = await this.client.providers.default.getAll('TABLENAME')
if (!table.length) return null

Having to fetch every single document in a table just to check if it has any documents isnt ideal. This is where the count comes in.

Hope it helps. Thanks Jacz

kyranet commented 5 years ago

This method is an extra, and honestly, if we were going for accepting all extras, this provider would easily end up with hundreds of them.

You can just use ReQL:

this.client.providers.default.db.table('tablename').count().run();

Why close this? Because this now falls under advanced usage of the provider, where you use the intentionally publicly exposed raw API from the driver.

tech6hutch commented 5 years ago

You can still add it in your own copy of the provider, of course, if you want the abstraction.