Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
GORM est un outil de mappage objet-relationnel pour le langage de programmation Go. Il fournit un framework permettant de mapper un modèle de domaine orienté objet sur une base de données relationnelle.
Vous pouvez intégrer des bases de données GoogleSQL à GORM à l'aide du dialecte Spanner Open Source (SpannerDialect).
Configurer GORM avec des bases de données Spanner en dialecte GoogleSQL
Pour utiliser le dialecte GORM GoogleSQL dans votre application, ajoutez l'instruction d'importation suivante au fichier où GORM est initialisé:
Utiliser GORM avec les bases de données Spanner en dialecte GoogleSQL
Pour en savoir plus sur les fonctionnalités et les recommandations d'utilisation de GORM avec Spanner, consultez la documentation de référence sur GitHub.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/05 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)."]]