func (c *Client) Close() {
	lock()
	defer unlock()
	c.close()
}
Close closes a database session.
package gorm
import (
	"context"
	"fmt"
	"sync"
	_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres"
	"github.com/apigee/registry/server/registry/internal/storage/models"
	"gorm.io/driver/postgres"
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
)
type Client struct {
	db *gorm.DB
}
var mutex sync.Mutex
var disableMutex bool
func lock() {
	if !disableMutex {
		mutex.Lock()
	}
}
func unlock() {
	if !disableMutex {
		mutex.Unlock()
	}
}
func NewClient(ctx context.Context, driver, dsn string) (*Client, error) {
	lock()
	switch driver {
	case "sqlite3":
		db, err := gorm.Open(sqlite.Open(dsn), &gorm.Config{
			Logger: NewGormLogger(ctx),
		})
		if err != nil {
			c := &Client{db: db}
			c.close()
			unlock()
			return nil, err
		}
		unlock()
		disableMutex = false
		c := &Client{db: db}
		c.ensure()
		return c, nil
	case "postgres", "cloudsqlpostgres":
		db, err := gorm.Open(postgres.New(postgres.Config{
			DriverName: driver,
			DSN:        dsn,
		}), &gorm.Config{
			Logger: NewGormLogger(ctx),
		})
		if err != nil {
			c := &Client{db: db}
			c.close()
			unlock()
			return nil, err
		}
		unlock()
		disableMutex = true
		c := &Client{db: db}
		c.ensure()
		return c, nil
	default:
		unlock()
		return nil, fmt.Errorf("unsupported database %s", driver)
	}
}