Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
GORM es una herramienta de asignación relacional de objetos para el lenguaje de programación Go.
Proporciona un framework para asignar un modelo de dominio orientado a objetos a una base de datos relacional.
Puedes integrar las bases de datos de PostgreSQL de Spanner con GORM usando el controlador pgx estándar de PostgreSQL y PGAdapter.
Configura GORM con bases de datos de dialecto PostgreSQL de Spanner
Asegúrate de que PGAdapter se ejecute en la misma máquina que la aplicación que se conecta con GORM con Spanner.
Agrega una sentencia de importación para el dialecto GORM de PostgreSQL a tu aplicación. Este es el mismo controlador que usarías normalmente con una base de datos de PostgreSQL.
Especifica localhost y 5432 como el host y el puerto del servidor de base de datos en la cadena de conexión de GORM. GORM requiere un nombre de usuario y una contraseña en la cadena de conexión. PGAdapter los ignora.
De manera opcional, especifica un número de puerto diferente si PGAdapter está configurado para escuchar en un puerto distinto del puerto predeterminado de PostgreSQL (5432).
PGAdapter no es compatible con SSL. De forma predeterminada, GORM primero intenta conectarse con SSL habilitado. Inhabilitar SSL en la solicitud de conexión acelera el proceso de conexión, ya que requiere un recorrido de ida y vuelta menos.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 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."]]