2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 19:29:02 +00:00
books/docs/server/backends.md

49 lines
1.0 KiB
Markdown
Raw Normal View History

2018-01-10 12:49:52 +00:00
# Backends
Frappe.js comes with built-in backends for data storage. These can be client-side or server-side
- SQLite
- REST
There can be only one backend at a time that can be accessed by the `frappe.db` property.
## API
The backend will implement the following `async` methods
- `get_doc`
- `get_all`
- `get_value`
- `insert`
- `update`
## sqlite Backend
Connection paramter required for the sqlite backend is the path of the file
```js
2018-01-16 06:09:17 +00:00
sqllite = require('frappejs/frappe/backends/sqlite');
2018-01-10 12:49:52 +00:00
2018-02-22 07:36:28 +00:00
frappe.db = await new sqlite.Database({dbPath: dbPath})
2018-01-10 12:49:52 +00:00
```
### SQL Queries
You can also directly write SQL with `frappe.db.sql`
```js
all_todos = frappe.db.sql('select name from todo');
```
## REST Backend
For the client, the backend is the REST API that executes calls with web-requests.
Before using, you must initialize the `frappe.fetch` property with `window.fetch` or `node-fetch`
```js
2018-01-16 06:09:17 +00:00
const Database = require('frappejs/frappe/backends/rest_client').Database;
2018-01-10 12:49:52 +00:00
frappe.fetch = window.fetch.bind();
frappe.db = await new Database({server: server});
```