Some checks failed
App Prod-Parity E2E Dispatch / dispatch (push) Failing after 10s
CD Storybook UI / build (push) Failing after 3m25s
CD Storybook UI / dispatch (push) Has been skipped
CD deploy main / website-changed-files (push) Successful in 18m8s
CI Agent Skills / changed-files-check (push) Successful in 18m9s
CI Create App E2E minimal / changed-files-check (push) Successful in 24s
CI Create App / changed-files-check (push) Successful in 26s
CI Docs / changed-files-check (push) Successful in 26s
CI Emails / changed-files-check (push) Successful in 28s
CI Example App Hello World / changed-files-check (push) Successful in 23s
CI Front / changed-files-check (push) Has been skipped
CI Example App Postcard / changed-files-check (push) Successful in 27s
CI UI / changed-files-check (push) Has been skipped
CI Utils Test / changed-files-check (push) Successful in 45s
CI Twenty Apps / discover (push) Successful in 1m3s
CD deploy main / deploy-main (push) Failing after 3s
CI Agent Skills / agent-skills-validate (push) Has been skipped
CI Create App / create-app-test (lint) (push) Has been skipped
CI Emails / emails-test (push) Has been skipped
CI Front / front-task (lingui:compile) (push) Has been skipped
CI Front / front-task (lint) (push) Has been skipped
CI Example App Postcard / example-app-postcard (push) Has been skipped
CI UI / ui-task (lint) (push) Has been skipped
CI UI / ui-task (pack-size) (push) Has been skipped
CI UI / ui-task (size) (push) Has been skipped
CI UI / ui-task (test) (push) Has been skipped
CI UI / ui-task (typecheck) (push) Has been skipped
CI Utils Test / utils-test (push) Has been skipped
CI Twenty Apps / ${{ matrix.app.name }} (push) Has been skipped
CI Emails / ci-emails-status-check (push) Successful in 2s
CI Example App Hello World / ci-example-app-hello-world-status-check (push) Successful in 2s
CI Example App Postcard / ci-example-app-postcard-status-check (push) Successful in 3s
CI UI / ui-sb-test (push) Has been skipped
CI Utils Test / ci-utils-test-status-check (push) Successful in 2s
CI Twenty Apps / ci-twenty-apps-status-check (push) Successful in 2s
CI UI / ci-ui-status-check (push) Successful in 2s
CI Desktop / desktop (push) Failing after 1m8s
Push docs to Crowdin / Push documentation to Crowdin (push) Failing after 55s
Push translations to Crowdin / Extract and upload translations (push) Failing after 5s
Push website translations to Crowdin / Extract and upload website translations (push) Failing after 5s
CI Create App / create-app-test (test) (push) Has been skipped
CI Create App / create-app-test (typecheck) (push) Has been skipped
CI Docs / docs-lint (push) Has been skipped
CI Example App Hello World / example-app-hello-world (push) Has been skipped
CI Front / front-task (lingui:extract) (push) Has been skipped
CI Front / front-task (test) (push) Has been skipped
CI Front / front-task (typecheck) (push) Has been skipped
CI UI / ui-sb-build (push) Failing after 1m32s
CI Twenty Apps / ${{ matrix.app.name }} (${{ matrix.server-source }}) (push) Has been skipped
CI Agent Skills / agent-skills-publish (push) Has been skipped
CI Create App / ci-create-app-status-check (push) Successful in 2s
CI Agent Skills / agent-skills-remote-source (push) Has been skipped
CI Create App E2E minimal / create-app-e2e-minimal (push) Has been cancelled
CI E2E Main / e2e-test (push) Has been cancelled
CI Front / front-sb-build (push) Has been cancelled
CI Front / front-build (push) Has been cancelled
CI Create App E2E minimal / ci-create-app-e2e-minimal-status-check (push) Has been cancelled
CI E2E Main / ci-e2e-main-status-check (push) Has been cancelled
CI E2E Main / notify-main-ci-failure (push) Has been cancelled
CI E2E Main / qa-scout-comment (push) Has been cancelled
CI Front / front-sb-test (push) Has been cancelled
CI Front / front-sb-screenshots (push) Has been cancelled
CI Front / ci-front-status-check (push) Has been cancelled
DPA Sub-Processor Sync / sync-subprocessors (push) Failing after 3s
AI Catalog Sync / sync-catalog (push) Failing after 2s
102 lines
6.2 KiB
Plaintext
102 lines
6.2 KiB
Plaintext
---
|
|
title: Panoramica
|
|
description: Definisci i dati che la tua app aggiunge a uno spazio di lavoro — oggetti, campi e relazioni.
|
|
icon: database
|
|
---
|
|
|
|
Il **data layer** di un'app Twenty è l'insieme dei dati che la tua app *aggiunge* a uno spazio di lavoro — i nuovi tipi di record che dichiara, le colonne che aggiunge agli oggetti esistenti e come questi record si collegano tra loro.
|
|
|
|
```text
|
|
┌──────────────────────────────────────────────────┐
|
|
│ Object — a record type, e.g. PostCard │
|
|
│ ├─ Field (name, type, label) │
|
|
│ ├─ Field │
|
|
│ └─ Relation (link to another object) │
|
|
└──────────────────────────────────────────────────┘
|
|
│
|
|
├── lives in your app, OR
|
|
│
|
|
▼
|
|
┌──────────────────────────────────────────────────┐
|
|
│ Standard / other apps' objects │
|
|
│ └─ Field added by your app via defineField │
|
|
└──────────────────────────────────────────────────┘
|
|
```
|
|
|
|
## In questa sezione
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Oggetti" icon="table" href="/l/it/developers/extend/apps/data/objects">
|
|
`defineObject` — dichiara nuovi tipi di record con i propri campi.
|
|
</Card>
|
|
<Card title="Estendere gli oggetti" icon="wand-magic-sparkles" href="/l/it/developers/extend/apps/data/extending-objects">
|
|
`defineField` — aggiunge campi agli oggetti standard o di altre app.
|
|
</Card>
|
|
<Card title="Relazioni" icon="diagram-project" href="/l/it/developers/extend/apps/data/relations">
|
|
Connessioni bidirezionali `MANY_TO_ONE` / `ONE_TO_MANY` tra oggetti.
|
|
</Card>
|
|
<Card title="Tipi di attività della timeline" icon="clock-rotate-left" href="/l/it/developers/extend/apps/data/timeline-activity-types">
|
|
Definisci eventi di audit automatici ed eventi espliciti dell'app per le timeline dei record.
|
|
</Card>
|
|
</CardGroup>
|
|
|
|
## Entità in sintesi
|
|
|
|
| Entità | Scopo | Definito con |
|
|
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
|
|
| **Oggetto** | Un nuovo tipo di record personalizzato (ad es. PostCard, Invoice) con i propri campi | `defineObject()` |
|
|
| **Campo** | Una colonna su un oggetto. I campi autonomi possono estendere oggetti che non hai creato tu (ad es. aggiungere `loyaltyTier` a Company) | `defineField()` |
|
|
| **Relazione** | Un collegamento bidirezionale tra due oggetti — entrambi i lati sono dichiarati come campi | `defineField()` con `FieldType.RELATION` |
|
|
| **Indice** | Un indice di database per velocizzare una query ricorrente su uno dei tuoi oggetti | `defineIndex()` |
|
|
| **Tipo di attività della timeline** | Un evento di audit automatico o un evento di dominio esplicito visualizzato nelle timeline dei record | `defineTimelineActivityType()` |
|
|
|
|
L'SDK rileva questi elementi tramite analisi AST in fase di build, quindi l'organizzazione dei file dipende da te — la convenzione è `src/objects/`, `src/fields/`, `src/indexes/` e `src/timeline-activity-types/`. Gli UUID `universalIdentifier` stabili collegano tutto tra le varie distribuzioni.
|
|
|
|
## Indici (facoltativi)
|
|
|
|
Le app possono distribuire indici insieme ai loro oggetti per mantenere veloci le query ricorrenti. Il caso più comune è una colonna di stato o di chiave esterna che leggi spesso.
|
|
|
|
```ts src/indexes/post-card-status.index.ts
|
|
import { defineIndex } from 'twenty-sdk/define';
|
|
|
|
import {
|
|
POST_CARD_UNIVERSAL_IDENTIFIER,
|
|
STATUS_FIELD_UNIVERSAL_IDENTIFIER,
|
|
} from '../objects/post-card.object';
|
|
|
|
export default defineIndex({
|
|
universalIdentifier: 'b6e9d2a1-5a4c-46ca-9d52-42c8f02d1ff0',
|
|
objectUniversalIdentifier: POST_CARD_UNIVERSAL_IDENTIFIER,
|
|
fields: [
|
|
{
|
|
universalIdentifier: 'b6e9d2a1-5a4c-46ca-9d52-42c8f02d1ff1',
|
|
fieldUniversalIdentifier: STATUS_FIELD_UNIVERSAL_IDENTIFIER,
|
|
},
|
|
],
|
|
});
|
|
```
|
|
|
|
### Indici univoci
|
|
|
|
`defineIndex` accetta `isUnique: true` sia per l'univocità a singola colonna sia per quella multi-colonna. Questa è la primitiva consigliata — `defineField({ isUnique: true })` è deprecata e verrà rimossa in una futura release.
|
|
|
|
```ts
|
|
defineIndex({
|
|
universalIdentifier: '…',
|
|
objectUniversalIdentifier: PERSON_UNIVERSAL_IDENTIFIER,
|
|
isUnique: true,
|
|
fields: [{ universalIdentifier: '…', fieldUniversalIdentifier: EMAIL_FIELD_UNIVERSAL_IDENTIFIER }],
|
|
});
|
|
```
|
|
|
|
### Altri vincoli
|
|
|
|
* Le clausole `WHERE` parziali restano sotto il controllo dell'amministratore — le app non possono dichiararle.
|
|
* Ogni oggetto è limitato a 10 indici personalizzati (gli indici propri del framework non contano).
|
|
|
|
Ordina l'array `fields` nel modo in cui Postgres dovrebbe usarlo — la colonna più a sinistra per prima, come in un elenco telefonico. Gli indici non sono gratuiti: ogni scrittura sulla tabella li aggiorna. Aggiungine uno solo quando hai una query che ne ha bisogno.
|
|
|
|
<Note>
|
|
Cerchi **Application Config** o **Roles & Permissions**? Quelli descrivono l'app in sé piuttosto che i dati che aggiunge — si trovano sotto [Config](/l/it/developers/extend/apps/config/overview). Cerchi **Connections** (Linear, GitHub, Slack OAuth)? Quelle esistono per essere chiamate *dalle* funzioni di logica e si trovano sotto [Logic](/l/it/developers/extend/apps/logic/connections).
|
|
</Note>
|