sqldriver

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Overview

Example
package main

import (
	"database/sql"

	account2 "github.com/aliyun/aliyun-odps-go-sdk/odps/account"
	"github.com/aliyun/aliyun-odps-go-sdk/odps/restclient"
	"github.com/aliyun/aliyun-odps-go-sdk/sqldriver"
	"log"
)

func main() {
	var account = account2.AliyunAccountFromEnv()
	var endpoint = restclient.LoadEndpointFromEnv()

	config := sqldriver.NewConfig()
	config.Endpoint = endpoint
	config.AccessId = account.AccessId()
	config.AccessKey = account.AccessKey()
	config.ProjectName = "project_1"

	dsn := config.FormatDsn()
	db, err := sql.Open("odps", dsn)
	if err != nil {
		log.Fatalf("%+v", err)
	}

	rows, err := db.Query("select ti, si, i, bi, b, f, d from data_type_demo;", nil)
	if err != nil {
		log.Fatalf("%+v", err)
	}

	var ti int8
	var si int16
	var i int32
	var bi int64
	var b []byte
	var f float32
	var d float64

	for rows.Next() {
		err = rows.Scan(&ti, &si, &i, &bi, &b, &f, &d)
		if err != nil {
			log.Fatalf("%+v", err)
		}

		println(ti, si, i, bi, b, f, d)
	}

}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var NewConfig = odps.NewConfig
View Source
var NewConfigFromIni = odps.NewConfigFromIni

Functions

This section is empty.

Types

type Config

type Config = odps.Config

Config is a configuration parsed from a DSN string. If a new Config is created instead of being parsed from a DSN string, the NewConfig function should be used, which sets default values.

func ParseDSN

func ParseDSN(dsn string) (*Config, error)

ParseDSN dsn格式如下 http://AccessId:AccessKey@host:port/path?project=""&stsToken=""&tcpConnectionTimeout=30&httpTimeout=60 其中project参数为必填项

type NamedArgQuery

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

func NewNamedArgQuery

func NewNamedArgQuery(query string) NamedArgQuery

func (*NamedArgQuery) SetArg

func (n *NamedArgQuery) SetArg(name string, value interface{})

type OdpsDriver

type OdpsDriver struct{}

func (OdpsDriver) Open

func (d OdpsDriver) Open(name string) (driver.Conn, error)

type PositionArgQuery

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

func NewPositionArgQuery

func NewPositionArgQuery(query string) PositionArgQuery

func (*PositionArgQuery) SetArgs

func (p *PositionArgQuery) SetArgs(args ...interface{})

Jump to

Keyboard shortcuts

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