mssql

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 8 Imported by: 1

README

mssql

GoDoc Integration Go Report Card codecov Gitter chat

Microsoft SQL Server adapter for REL.

Example

package main

import (
	"context"

	_ "github.com/denisenkom/go-mssqldb"
	"github.com/go-rel/mssql"
	"github.com/go-rel/rel"
)

func main() {
	// open mssql connection.
	adapter, err := mssql.Open("sqlserver://sa:REL2021-mssql@localhost:1433?database=rel")
	if err != nil {
		panic(err)
	}
	defer adapter.Close()

	// initialize REL's repo.
	repo := rel.New(adapter)
	repo.Ping(context.TODO())
}

Supported Driver

  • github.com/denisenkom/go-mssqldb

Supported Database

  • Microsoft SQL Server 2017
  • Microsoft SQL Server 2019

Testing

Start Microsoft SQL server in Docker
docker run -it --rm -p 1434:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=REL2021-mssql" -e "MSSQL_PID=Developer"  mcr.microsoft.com/mssql/server:2019-latest
Run tests
MSSQL_DATABASE="sqlserver://sa:REL2021-mssql@localhost:1434" go test ./...

Documentation

Overview

Package mssql wraps mssql driver as an adapter for REL.

Example
package main

import (
	"context"

	_ "github.com/denisenkom/go-mssqldb"
	"github.com/go-rel/mssql"
	"github.com/go-rel/rel"
)

func main() {
	// open mssql connection.
	adapter, err := mssql.Open("sqlserver://sa:REL2021-mssql@localhost:1433?database=rel")
	if err != nil {
		panic(err)
	}
	defer adapter.Close()

	// initialize REL's repo.
	repo := rel.New(adapter)
	repo.Ping(context.TODO())
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(db *db.DB) rel.Adapter

New mssql adapter using existing connection.

func Open

func Open(dsn string) (rel.Adapter, error)

Open mssql connection using dsn.

Types

type MSSQL added in v0.4.0

type MSSQL struct {
	sql.SQL
}

MSSQL Adapter.

func (MSSQL) Begin added in v0.4.0

func (m MSSQL) Begin(ctx context.Context) (rel.Adapter, error)

Begin begins a new transaction.

func (MSSQL) Insert added in v0.4.0

func (m MSSQL) Insert(ctx context.Context, query rel.Query, primaryField string, mutates map[string]rel.Mutate) (interface{}, error)

Insert inserts a record to database and returns its id.

func (MSSQL) InsertAll added in v0.4.0

func (m MSSQL) InsertAll(ctx context.Context, query rel.Query, primaryField string, fields []string, bulkMutates []map[string]rel.Mutate) ([]interface{}, error)

InsertAll inserts multiple records to database and returns its ids.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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