---
title: Database
project: Total.js Flow
version: 11.1
section: components
language: it
license: MIT
url: https://totaljs.es/docs/it/flow/11-1/components/databases/
updated: 2026-11-20T06:50:57.962Z
---

# Database

> Componenti che leggono e scrivono dati nei database.

Componenti che leggono e scrivono dati nei database. Questa pagina contiene il gruppo del catalogo **Databases**.

Ogni voce elenca gli ingressi e le uscite del componente, le sue impostazioni principali e il testo del suo readme. Per aggiungere un componente a un FlowStream, consulta [Scaricare i componenti](/flow/11-1/guides/download-components/).

## API

### influxdb.html · version 1

Type: `component`

Scrive dati in InfluxDB o esegue una query Flux.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | no |  | URL del server. |
| `token` | `String` | no |  | Token. |
| `org` | `String` | no |  | Organizzazione. |
| `bucket` | `String` | no |  | Bucket. |
| `api` | `String` | no |  | Azione. Una tra: `write` (Write data), `query` (Execute a Flux query). |
| `fields` | `String` | no |  | Campi. |
| `tags` | `String` | no |  | Tag. |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

Flow installa il pacchetto npm `@influxdata/influxdb-client` quando aggiungi il componente.

**Ingresso**

Dati attesi per "Write data":

```js
{
    measurement: '<measurement-name>',
	fields: {
        fieldname: <fieldvalue>,
    },
    tags: {
        tagname: '<tagvalue>'
    }
}
```

Dati attesi per "Execute a Flux query":

```js
{
    query: 'from(bucket: "Some Bucket") |> range(start: -1h)'
}
```

### localstorage.html · version 1

Type: `component`

Conserva dati per poco tempo e li rilegge.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `savekey` | `String` | no | `id` | Chiave di salvataggio. |
| `readkey` | `String` | no | `id` | Chiave di lettura. |
| `path` | `String` | no |  | Dove salvare i dati? |
| `remove` | `Boolean` | no | `true` | Rimuovi l'elemento dopo la lettura. |
| `expire` | `String` | no | `1 hour` | Scadenza. |

**Ingressi:** `save` (Save), `read` (Read).  
**Uscite:** `output` (Output), `error` (Error).

Questo componente offre un piccolo e semplice archivio persistente. Puoi salvare i dati per un breve periodo e leggerli quando ti servono.

### mongodb-insert.html · version 1

Type: `component`

Inserisce documenti in MongoDB.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no |  | Nome della connessione. |
| `connection` | `String` | no |  | Stringa di connessione (senza il nome del database). |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

Flow installa il pacchetto npm `mongodb@4.0.0` quando aggiungi il componente.

**Ingresso**

Esempio

```javascript
{
    database: 'database-name',
    collection: 'collection-name',
	data: { ... },  // data to insert, object for `insertOne` and an array of objects for `insertMany`
	options: { ... }// insert options as passed to `insertOne(data, options)` or `insertMany(data, options)`
}
```

### mongodb-query.html · version 2

Type: `component`

Esegue query su MongoDB.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `String` | no | `return query.find();` | Editor della query. |
| `name` | `String` | no |  | Nome della connessione. |
| `connection` | `String` | no |  | Stringa di connessione (senza il nome del database). |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

Flow installa i pacchetti npm `mongodb@4.0.0`, `mquery` quando aggiungi il componente.

Dietro le quinte usa mquery. Ecco la [documentazione](https://www.npmjs.com/package/mquery)

**Ingresso**

Esempio

```javascript
{
    database: 'database-name',
    collection: 'collection-name',
	data: <any> // this prop will be passed into the query function
}
```

**Editor della query**

```js
// query; mquery instance
// data; data from the incomming object

return query.find(); // return all documents
```

**Importante**

In `.select()` non puoi usare inclusione ed esclusione insieme.
Questo non è valido: `.select('firstname -lastname')`
Esclusione valida: `.select('-lastname')` o `.select('-email -lastname')` ecc.
Inclusione valida: `.select('name email')` o `.select('email lastname')` ecc.

### mysql.html · version 2

Type: `component`

Esegue query SQL su un database MySQL.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `connection` | `String` | no |  | Stringa di connessione. |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

Flow installa il pacchetto npm `mysql2` quando aggiungi il componente.

**Ingresso**

Dati attesi:

```javascript
{
	query: 'SELECT * FROM tblname;'
}
```

### nosql.html · version 1

Type: `component`

Inserisce, legge, interroga, aggiorna e rimuove documenti nel database NoSQL di Total.js.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `collection` | `String` | no |  | Nome della collezione (tabella) del DB. |
| `method` | `String` | no |  | Metodo. Uno tra: `insert` (Insert), `update` (Update), `read` (Read), `query` (Query), `remove` (Remove). |
| `addid` | `String` | no |  | Aggiungi un ID univoco alla proprietà `id` dei dati prima dell'inserimento. |
| `upsert` | `String` | no |  | Inserisci il documento se non esiste. |
| `upsertid` | `String` | no |  | Aggiungi un ID univoco alla proprietà `id` dei dati prima dell'inserimento (solo se non esiste). |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

**Uscite**

- risposta del motore NoSQL

**Impostazioni**

- collection: (facoltativo) se non è impostato, l'oggetto dei dati in arrivo deve avere la proprietà 'collection'
- method: (facoltativo) se non è impostato, l'oggetto dei dati in arrivo deve avere la proprietà 'method'

**Ingresso**

```javascript
{
	collection: 'users', // optional, will override settings value
	method: 'query', // insert|read|query|update|remove - optional, will override settings value
	// for insert, update
	data: { ... },
	// for query, read, update, remove
	filter: [
		['where', 'sensor', 'temp'], // builder.where('sensor', 'temp');
		['limit', 2]                 // builder.limit(2);
	],
	upsert: true // only for update, if set then document will be inserted if it doesn't exist
	addid: true  // only for insert and update, if set then id prop will be automaticaly generated (for update only when upsert is also set)
}
```

**Insert**

- inserisce i dati ricevuti
- si aspetta che i dati siano un Object
- restituisce error, success, id

**Read**

- restituisce il primo documento trovato
- richiede `filter`
- restituisce error, response

**Update**

- aggiorna uno o più documenti
- si aspetta che i dati siano un Object con tutte le proprietà da aggiornare
- richiede `filter`
- restituisce error, response
- se response è 0, l'aggiornamento non è riuscito

**Remove**

- rimuove il documento
- richiede `filter`
- restituisce error, response
- se response è 0, la rimozione non è riuscita

**Query**

- restituisce tutti i documenti trovati
- richiede `filter`
- restituisce error, response

### postgresql.html · version 2

Type: `component`

Esegue query SQL su un database PostgreSQL.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `connection` | `String` | no |  | Stringa di connessione. |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output).

Flow installa il pacchetto npm `pg` quando aggiungi il componente.

PostgreSQL

**Ingresso**

Dati attesi:

```javascript
{
	query: 'SELECT * FROM tblname;'
}
```

Uscita:

```javascript
{
	command: 'INSERT', // SELECT, etc.
	rows: [], //
	rowCount: 1
}
```

### sqlite3.html · version 2

Type: `component`

Esegue query su un database SQLite3.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no |  | Nome del file (facoltativo). |

**Ingressi:** `input` (Input).  
**Uscite:** `output` (Output), `error` (Error).

Flow installa il pacchetto npm `better-sqlite3` quando aggiungi il componente.

SQLite3 [Documentazione](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md)

```js
{
	// query
	prepare: 'INSERT INTO cats (name, age) VALUES (?, ?)',

	// function name: run, get, all, exec
	fn: 'run',

	// data, optional
	data: ['Joey', 2] // string/number or array

}
```

__Funzioni:__

- [run](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#runbindparameters---object)
- [get](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#getbindparameters---row)
- [all](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#allbindparameters---array-of-rows)
- [exec](https://github.com/JoshuaWise/better-sqlite3/blob/HEAD/docs/api.md#execstring---this)
