Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 2.04 KB

README.md

File metadata and controls

58 lines (45 loc) · 2.04 KB

GORM YDB Driver

YDB support for GORM

License Release PkgGoDev tests lint Go Report Card codecov Code lines View examples Telegram WebSite

Quick Start

You can simply test your connection to your database with the following:

package main

import (
	ydb "github.com/ydb-platform/gorm-driver"
	"gorm.io/gorm"
)

type User struct {
	Name string `gorm:"primarykey"`
	Age  int
}

func main() {
	db, err := gorm.Open(ydb.Open("grpc://localhost:2136/local"))
	if err != nil {
		panic("failed to connect database")
	}

	// Auto Migrate
	db.AutoMigrate(&User{})

	// Insert
	db.Create(&User{Name: "Angeliz", Age: 18})

	// Select
	db.Find(&User{}, "name = ?", "Angeliz")

	// Batch Insert
	user1 := User{Name: "Charles", Age: 12}
	user2 := User{Name: "Feynman", Age: 13}
	user3 := User{Name: "Michael", Age: 14}
	users := []User{user1, user2, user3}
	db.Create(&users)

	// ...
}