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 con il dialetto GoogleSQL con GORM utilizzando il dialetto Spanner open source (SpannerDialect).
Configurare GORM con i database con dialetto GoogleSQL di Spanner
Per utilizzare il dialetto GORM di GoogleSQL nella tua applicazione,
aggiungi la seguente dichiarazione di importazione al file in cui viene inizializzato GORM:
[[["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 (GoogleSQL dialect)\n\nGORM is an object-relational mapping tool for the Go programming language. It provides a framework for mapping an object-oriented domain model to a relational database.\n\nYou can integrate GoogleSQL-dialect databases with GORM using the open source\n[Spanner Dialect](https://github.com/googleapis/go-gorm-spanner)\n(`SpannerDialect`).\n\nSet up GORM with Spanner GoogleSQL-dialect databases\n----------------------------------------------------\n\nTo use the GoogleSQL GORM dialect in your application,\nadd the following import statement to the file where GORM is initialized: \n\n import (\n \"fmt\"\n\n \"gorm.io/gorm\"\n _ \"github.com/googleapis/go-sql-spanner\"\n spannergorm \"github.com/googleapis/go-gorm-spanner\"\n )\n\n dsn := fmt.Sprintf(\"projects/%s/instances/%s/databases/%s\", projectId, instanceId, databaseId),\n db, err := gorm.Open(spannergorm.New(spannergorm.Config{DriverName: \"spanner\", DSN: dsn}), &gorm.Config{})\n\nSee the [GORM with GoogleSQL documentation](https://github.com/googleapis/go-sql-spanner/blob/-/driver.go)\nfor more connection options for Spanner.\n\nUse GORM with Spanner GoogleSQL-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/googleapis/go-gorm-spanner)\non GitHub.\n\nWhat's next\n-----------\n\n- Checkout the [sample application](https://github.com/googleapis/go-gorm-spanner/blob/-/samples/helloworld/main.go) using GORM with GoogleSQL and Spanner.\n- Learn more about [GORM](https://gorm.io/).\n- [File a GitHub issue](https://github.com/googleapis/go-gorm-spanner/issues) to report a bug or ask a question about using GORM with Spanner with GoogleSQL.\n- Learn more about [Integrate Spanner with GORM (PostgreSQL dialect)](/spanner/docs/use-gorm-postgresql)."]]