sqlserver

package module
v0.0.0-...-ff5ac8c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2025 License: MIT Imports: 25 Imported by: 1

README

Sqlserver

The Sqlserver driver for facades.Orm() of Goravel.

Version

goravel/sqlserver goravel/framework
v1.0.* v1.16.*

Install

  1. Add package
go get -u github.com/goravel/sqlserver
  1. Register service provider
// config/app.go
import "github.com/goravel/sqlserver"

"providers": []foundation.ServiceProvider{
    ...
    &sqlserver.ServiceProvider{},
}
  1. Add Sqlserver driver to config/database.go file
// config/database.go
import (
    "github.com/goravel/framework/contracts/database/driver"
    "github.com/goravel/sqlserver/contracts"
    sqlserverfacades "github.com/goravel/sqlserver/facades"
)

"connections": map[string]any{
    ...
    "sqlserver": map[string]any{
        "host":     config.Env("DB_HOST", "127.0.0.1"),
        "port":     config.Env("DB_PORT", 3306),
        "database": config.Env("DB_DATABASE", "forge"),
        "username": config.Env("DB_USERNAME", ""),
        "password": config.Env("DB_PASSWORD", ""),
        "charset":  "utf8mb4",
        "prefix":   "",
        "singular": false,
        "via": func() (driver.Driver, error) {
            return sqlserverfacades.Sqlserver("sqlserver")
        },
        // Optional
        "dsn": "",
        "read": []contracts.Config{
            {Host: "192.168.1.1", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
        },
        "write": []contracts.Config{
            {Host: "192.168.1.2", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
        },
    },
}

Schema

If you want to specify a schema, you can add the schema in the TableName function of the model.

func (r *User) TableName() string {
  return "goravel.users"
}

Documentation

Index

Constants

View Source
const (
	Binding = "goravel.sqlserver"
	Name    = "SQL Server"
)

Variables

View Source
var (
	FailedToGenerateDSN = errors.New("failed to generate DSN, please check the database configuration")
	ConfigNotFound      = errors.New("not found database configuration")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(config config.Config, connection string) *Config

func (*Config) Config

func (r *Config) Config() config.Config

func (*Config) Connection

func (r *Config) Connection() string

func (*Config) Readers

func (r *Config) Readers() []contracts.FullConfig

func (*Config) Writers

func (r *Config) Writers() []contracts.FullConfig

type Docker

type Docker struct {
	// contains filtered or unexported fields
}

func NewDocker

func NewDocker(config contracts.ConfigBuilder, database, username, password string) *Docker

func (*Docker) Build

func (r *Docker) Build() error

func (*Docker) Config

func (*Docker) Database

func (r *Docker) Database(name string) (contractsdocker.DatabaseDriver, error)

func (*Docker) Driver

func (r *Docker) Driver() string

func (*Docker) Fresh

func (r *Docker) Fresh() error

func (*Docker) Image

func (r *Docker) Image(image contractsdocker.Image)

func (*Docker) Ready

func (r *Docker) Ready() error

func (*Docker) Reuse

func (r *Docker) Reuse(containerID string, port int) error

func (*Docker) Shutdown

func (r *Docker) Shutdown() error

type Exprs

type Exprs []clause.Expression

func (Exprs) Build

func (exprs Exprs) Build(builder clause.Builder)

type Grammar

type Grammar struct {
	// contains filtered or unexported fields
}

func NewGrammar

func NewGrammar(prefix string) *Grammar

func (*Grammar) CompileAdd

func (r *Grammar) CompileAdd(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileChange

func (r *Grammar) CompileChange(blueprint driver.Blueprint, command *driver.Command) []string

func (*Grammar) CompileColumns

func (r *Grammar) CompileColumns(_, table string) (string, error)

func (*Grammar) CompileComment

func (r *Grammar) CompileComment(_ driver.Blueprint, _ *driver.Command) string

func (*Grammar) CompileCreate

func (r *Grammar) CompileCreate(blueprint driver.Blueprint) string

func (*Grammar) CompileDefault

func (r *Grammar) CompileDefault(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileDrop

func (r *Grammar) CompileDrop(blueprint driver.Blueprint) string

func (*Grammar) CompileDropAllDomains

func (r *Grammar) CompileDropAllDomains(_ []string) string

func (*Grammar) CompileDropAllForeignKeys

func (r *Grammar) CompileDropAllForeignKeys() string

func (*Grammar) CompileDropAllTables

func (r *Grammar) CompileDropAllTables(_ string, _ []driver.Table) []string

func (*Grammar) CompileDropAllTypes

func (r *Grammar) CompileDropAllTypes(_ string, _ []driver.Type) []string

func (*Grammar) CompileDropAllViews

func (r *Grammar) CompileDropAllViews(_ string, _ []driver.View) []string

func (*Grammar) CompileDropColumn

func (r *Grammar) CompileDropColumn(blueprint driver.Blueprint, command *driver.Command) []string

func (*Grammar) CompileDropDefaultConstraint

func (r *Grammar) CompileDropDefaultConstraint(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileDropForeign

func (r *Grammar) CompileDropForeign(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileDropFullText

func (r *Grammar) CompileDropFullText(_ driver.Blueprint, _ *driver.Command) string

func (*Grammar) CompileDropIfExists

func (r *Grammar) CompileDropIfExists(blueprint driver.Blueprint) string

func (*Grammar) CompileDropIndex

func (r *Grammar) CompileDropIndex(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileDropPrimary

func (r *Grammar) CompileDropPrimary(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileDropUnique

func (r *Grammar) CompileDropUnique(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileForeign

func (r *Grammar) CompileForeign(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileForeignKeys

func (r *Grammar) CompileForeignKeys(schema, table string) string

func (*Grammar) CompileFullText

func (r *Grammar) CompileFullText(_ driver.Blueprint, _ *driver.Command) string

func (*Grammar) CompileInRandomOrder

func (r *Grammar) CompileInRandomOrder(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompileIndex

func (r *Grammar) CompileIndex(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileIndexes

func (r *Grammar) CompileIndexes(_, table string) (string, error)

func (*Grammar) CompileJsonContains

func (r *Grammar) CompileJsonContains(column string, value any, isNot bool) (string, []any, error)

func (*Grammar) CompileJsonContainsKey

func (r *Grammar) CompileJsonContainsKey(column string, isNot bool) string

func (*Grammar) CompileJsonLength

func (r *Grammar) CompileJsonLength(column string) string

func (*Grammar) CompileJsonSelector

func (r *Grammar) CompileJsonSelector(column string) string

func (*Grammar) CompileJsonValues

func (r *Grammar) CompileJsonValues(args ...any) []any

func (*Grammar) CompileLimit

func (r *Grammar) CompileLimit(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompileLockForUpdate

func (r *Grammar) CompileLockForUpdate(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompileLockForUpdateForGorm

func (r *Grammar) CompileLockForUpdateForGorm() clause.Expression

func (*Grammar) CompileOffset

func (r *Grammar) CompileOffset(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompileOrderBy

func (r *Grammar) CompileOrderBy(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompilePlaceholderFormat

func (r *Grammar) CompilePlaceholderFormat() driver.PlaceholderFormat

func (*Grammar) CompilePrimary

func (r *Grammar) CompilePrimary(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileRandomOrderForGorm

func (r *Grammar) CompileRandomOrderForGorm() string

func (*Grammar) CompileRename

func (r *Grammar) CompileRename(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileRenameColumn

func (r *Grammar) CompileRenameColumn(blueprint driver.Blueprint, command *driver.Command, _ []driver.Column) (string, error)

func (*Grammar) CompileRenameIndex

func (r *Grammar) CompileRenameIndex(blueprint driver.Blueprint, command *driver.Command, _ []driver.Index) []string

func (*Grammar) CompileSharedLock

func (r *Grammar) CompileSharedLock(builder sq.SelectBuilder, conditions *driver.Conditions) sq.SelectBuilder

func (*Grammar) CompileSharedLockForGorm

func (r *Grammar) CompileSharedLockForGorm() clause.Expression

func (*Grammar) CompileTableComment

func (r *Grammar) CompileTableComment(_ driver.Blueprint, _ *driver.Command) string

func (*Grammar) CompileTables

func (r *Grammar) CompileTables(_ string) string

func (*Grammar) CompileTypes

func (r *Grammar) CompileTypes() string

func (*Grammar) CompileUnique

func (r *Grammar) CompileUnique(blueprint driver.Blueprint, command *driver.Command) string

func (*Grammar) CompileVersion

func (r *Grammar) CompileVersion() string

func (*Grammar) CompileViews

func (r *Grammar) CompileViews(_ string) string

func (*Grammar) GetAttributeCommands

func (r *Grammar) GetAttributeCommands() []string

func (*Grammar) ModifyDefault

func (r *Grammar) ModifyDefault(_ driver.Blueprint, column driver.ColumnDefinition) string

func (*Grammar) ModifyIncrement

func (r *Grammar) ModifyIncrement(blueprint driver.Blueprint, column driver.ColumnDefinition) string

func (*Grammar) ModifyNullable

func (r *Grammar) ModifyNullable(_ driver.Blueprint, column driver.ColumnDefinition) string

func (*Grammar) TypeBigInteger

func (r *Grammar) TypeBigInteger(_ driver.ColumnDefinition) string

func (*Grammar) TypeBoolean

func (r *Grammar) TypeBoolean(_ driver.ColumnDefinition) string

func (*Grammar) TypeChar

func (r *Grammar) TypeChar(column driver.ColumnDefinition) string

func (*Grammar) TypeDate

func (r *Grammar) TypeDate(_ driver.ColumnDefinition) string

func (*Grammar) TypeDateTime

func (r *Grammar) TypeDateTime(column driver.ColumnDefinition) string

func (*Grammar) TypeDateTimeTz

func (r *Grammar) TypeDateTimeTz(column driver.ColumnDefinition) string

func (*Grammar) TypeDecimal

func (r *Grammar) TypeDecimal(column driver.ColumnDefinition) string

func (*Grammar) TypeDouble

func (r *Grammar) TypeDouble(_ driver.ColumnDefinition) string

func (*Grammar) TypeEnum

func (r *Grammar) TypeEnum(column driver.ColumnDefinition) string

func (*Grammar) TypeFloat

func (r *Grammar) TypeFloat(column driver.ColumnDefinition) string

func (*Grammar) TypeInteger

func (r *Grammar) TypeInteger(_ driver.ColumnDefinition) string

func (*Grammar) TypeJson

func (r *Grammar) TypeJson(_ driver.ColumnDefinition) string

func (*Grammar) TypeJsonb

func (r *Grammar) TypeJsonb(_ driver.ColumnDefinition) string

func (*Grammar) TypeLongText

func (r *Grammar) TypeLongText(_ driver.ColumnDefinition) string

func (*Grammar) TypeMediumInteger

func (r *Grammar) TypeMediumInteger(_ driver.ColumnDefinition) string

func (*Grammar) TypeMediumText

func (r *Grammar) TypeMediumText(_ driver.ColumnDefinition) string

func (*Grammar) TypeSmallInteger

func (r *Grammar) TypeSmallInteger(_ driver.ColumnDefinition) string

func (*Grammar) TypeString

func (r *Grammar) TypeString(column driver.ColumnDefinition) string

func (*Grammar) TypeText

func (r *Grammar) TypeText(_ driver.ColumnDefinition) string

func (*Grammar) TypeTime

func (r *Grammar) TypeTime(column driver.ColumnDefinition) string

func (*Grammar) TypeTimeTz

func (r *Grammar) TypeTimeTz(column driver.ColumnDefinition) string

func (*Grammar) TypeTimestamp

func (r *Grammar) TypeTimestamp(column driver.ColumnDefinition) string

func (*Grammar) TypeTimestampTz

func (r *Grammar) TypeTimestampTz(column driver.ColumnDefinition) string

func (*Grammar) TypeTinyInteger

func (r *Grammar) TypeTinyInteger(_ driver.ColumnDefinition) string

func (*Grammar) TypeTinyText

func (r *Grammar) TypeTinyText(_ driver.ColumnDefinition) string

type Processor

type Processor struct {
}

func NewProcessor

func NewProcessor() *Processor

func (Processor) ProcessColumns

func (r Processor) ProcessColumns(dbColumns []driver.DBColumn) []driver.Column

func (Processor) ProcessForeignKeys

func (r Processor) ProcessForeignKeys(dbForeignKeys []driver.DBForeignKey) []driver.ForeignKey

func (Processor) ProcessIndexes

func (r Processor) ProcessIndexes(dbIndexes []driver.DBIndex) []driver.Index

func (Processor) ProcessTypes

func (r Processor) ProcessTypes(types []driver.Type) []driver.Type

type ServiceProvider

type ServiceProvider struct {
}

func (*ServiceProvider) Boot

func (receiver *ServiceProvider) Boot(app foundation.Application)

func (*ServiceProvider) Register

func (receiver *ServiceProvider) Register(app foundation.Application)

type Sqlserver

type Sqlserver struct {
	// contains filtered or unexported fields
}

func NewSqlserver

func NewSqlserver(config config.Config, log log.Log, connection string) *Sqlserver

func (*Sqlserver) Docker

func (r *Sqlserver) Docker() (docker.DatabaseDriver, error)

func (*Sqlserver) Grammar

func (r *Sqlserver) Grammar() driver.Grammar

func (*Sqlserver) Pool

func (r *Sqlserver) Pool() database.Pool

func (*Sqlserver) Processor

func (r *Sqlserver) Processor() driver.Processor

type WithHint

type WithHint struct {
	Type string
	Keys []string
}

func With

func With(names ...string) WithHint

func (WithHint) Build

func (indexHint WithHint) Build(builder clause.Builder)

func (WithHint) ModifyStatement

func (indexHint WithHint) ModifyStatement(stmt *gorm.Statement)

type Wrap

type Wrap struct {
	*schema.Wrap
}

func NewWrap

func NewWrap(prefix string) *Wrap

func (*Wrap) Quotes

func (r *Wrap) Quotes(value []string) []string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL