Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
GORM è uno strumento di mappatura relazionale degli oggetti per il linguaggio di programmazione Go.
Fornisce un framework per mappare un modello di dominio orientato agli oggetti a un database relazionale.
Puoi integrare i database PostgreSQL di Spanner con GORM utilizzando il driver pgx PostgreSQL standard e PGAdapter.
Configurare GORM con i database in dialetto PostgreSQL di Spanner
Assicurati che PGAdapter sia in esecuzione sulla stessa macchina dell'applicazione che si connette utilizzando GORM con Spanner.
Aggiungi un'istruzione di importazione per il dialetto GORM di PostgreSQL alla tua applicazione. Si tratta dello stesso driver che utilizzeresti normalmente con un database PostgreSQL.
Specifica localhost e 5432 come host e porta del server del database nella stringa di connessione GORM. GORM richiede un nome utente e una password nella stringa di connessione. PGAdapter li ignora.
Se vuoi, specifica un numero di porta diverso se PGAdapter è configurato per ascoltare su una porta diversa dalla porta PostgreSQL predefinita (5432).
PGAdapter non supporta SSL. Per impostazione predefinita, GORM tenta prima di connettersi con SSL abilitato. La disattivazione di SSL nella richiesta di connessione accelera la procedura di connessione, in quanto richiede un numero inferiore di viaggi di andata e ritorno.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-05 UTC."],[],[],null,["# Integrate Spanner with GORM (PostgreSQL dialect)\n\nGORM is an object-relational mapping tool for the Go programming language.\nIt provides a framework for mapping an object-oriented domain model to a relational database.\n\nYou can integrate Spanner PostgreSQL databases with GORM using the standard PostgreSQL pgx driver and PGAdapter.\n\nSet up GORM with Spanner PostgreSQL-dialect databases\n-----------------------------------------------------\n\n1. Ensure that PGAdapter is running on the same machine as the\n application that is connecting using GORM with Spanner.\n\n For more information, see [Start PGAdapter](/spanner/docs/pgadapter-start).\n2. Add an import statement for the PostgreSQL GORM dialect\n to your application. This is the same driver as you would normally use with a\n PostgreSQL database.\n\n3. Specify `localhost` and `5432` as the database server host and port in the\n GORM connection string. GORM requires a\n username and password in the connection string. PGAdapter ignores these.\n\n - Optionally, specify a different port number if PGAdapter is configured to listen on a port other than the default PostgreSQL port (5432).\n - PGAdapter does not support SSL. GORM by default first tries to connect with SSL enabled. Disabling SSL in the connection request speeds up the connection process, because it requires one fewer round trip.\n\n import (\n \"gorm.io/driver/postgres\"\n \"gorm.io/gorm\"\n )\n\n dsn := \"host=localhost user=gorm password=gorm dbname=gorm port=5432 sslmode=disable\"\n db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})\n\nSee the [GORM with PostgreSQL documentation](https://gorm.io/docs/connecting_to_the_database.html#PostgreSQL)\nfor more connection options for PostgreSQL.\n\nUse GORM with Spanner PostgreSQL-dialect databases\n--------------------------------------------------\n\nFor more information about the features and recommendations\nfor using GORM with Spanner, consult the\n[reference documentation](https://github.com/GoogleCloudPlatform/pgadapter/blob/-/samples/golang/gorm)\non GitHub.\n\nWhat's next\n-----------\n\n- Checkout the [sample application](https://github.com/GoogleCloudPlatform/pgadapter/blob/-/samples/golang/gorm/sample.go) using GORM with PGAdapter and Spanner.\n- Learn more about [GORM](https://gorm.io/).\n- Learn more about [PGAdapter](/spanner/docs/pgadapter).\n- [File a GitHub issue](https://github.com/GoogleCloudPlatform/pgadapter/issues) to report a bug or ask a question about using GORM with Spanner with PGAdapter."]]