Mengintegrasikan Spanner dengan GORM (dialek GoogleSQL)
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
GORM adalah alat pemetaan relasional objek untuk bahasa pemrograman Go. Framework ini menyediakan framework untuk memetakan model domain berorientasi objek ke database relasional.
Anda dapat mengintegrasikan database dialek GoogleSQL dengan GORM menggunakan Dialek Spanner open source (SpannerDialect).
Menyiapkan GORM dengan database dialek GoogleSQL Spanner
Untuk menggunakan dialek GORM GoogleSQL di aplikasi Anda,
tambahkan pernyataan impor berikut ke file tempat GORM diinisialisasi:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]