Stay organized with collections
Save and categorize content based on your preferences.
GORM 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.
You can integrate GoogleSQL-dialect databases with GORM using the open source
Spanner Dialect
(SpannerDialect).
Set up GORM with Spanner GoogleSQL-dialect databases
To use the GoogleSQL GORM dialect in your application,
add the following import statement to the file where GORM is initialized:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 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)."]]