# Use the DATA API to switch databases

> DATA addresses a table as database/table, so the same query code works with the embedded NoSQL and with other databases.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: fa4d9b6515a2a695cd7f63b74ef0727aad586452f23b903a239efdd0792b4dbf
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

`DATA` is a database-agnostic entry point to the query builder. The first argument is `driver/table`; `nosql/people` means "the embedded NoSQL database, table `people`". The builder methods (`where`, `sort`, `take`, `callback`) are the same you use with `NOSQL()`, so the code of your actions stays the same if you later replace the driver.

| Call | Does |
|---|---|
| `DATA.insert(table, doc)` | inserts a document |
| `DATA.find(table)` | returns a builder for a list |
| `DATA.read(table)` | returns a builder for one document |
| `DATA.update(table, data)` | updates documents |
| `DATA.remove(table)` | removes documents |

```js definitions/people.js
NEWACTION('People/insert', {
	name: 'Insert a person',
	input: '*name:String, age:Number',
	action: function($, model) {
		model.id = UID();
		DATA.insert('nosql/people', model).callback(() => $.success(model.id));
	}
});

NEWACTION('People/query', {
	name: 'List people',
	query: 'sort:Lowercase',
	action: function($) {
		DATA.find('nosql/people').sort($.query.sort || 'name_asc').callback((err, response) => $.callback(response));
	}
});

NEWACTION('People/rename', {
	name: 'Rename a person',
	params: '*id:UID',
	input: '*name:String',
	action: function($, model) {
		DATA.update('nosql/people', { name: model.name }).where('id', $.params.id).callback((err, count) => $.success(count));
	}
});
```

```js controllers/people.js
exports.install = function() {
	ROUTE('POST /people/ --> *People/insert');
	ROUTE('GET /people/ --> *People/query');
	ROUTE('PATCH /people/{id}/ --> *People/rename');
};
```
