mydb

package module
v0.0.0-...-547216b Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

simple golang db driver learning

Documentation

Overview

Package mydb mydb struct

Example
package main

import (
	"database/sql"
	"log"

	_ "github.com/rongfengliang/mysqldriver"
)

func main() {
	db, err := sql.Open("mydb", "mydb://dalong@127.0.0.1/demoapp")
	if err != nil {
		log.Fatalf("some error %s", err.Error())
	}
	rows, err := db.Query("select * from demoapp")
	if err != nil {
		log.Println("some wrong for query", err.Error())
	}
	for rows.Next() {
		rows.Scan()
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
}

Conn for db open

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

Begin begin

func (*Conn) Close

func (c *Conn) Close() error

Close close db connection

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare statement for prepare exec

type Driver

type Driver struct {
}

Driver mydb driver for implement database/sql/driver

func (*Driver) Open

func (driver *Driver) Open(name string) (driver.Conn, error)

Open for implement driver interface

type MyRowS

type MyRowS struct {
	Size int64
}

MyRowS myRowS implemmet for driver.Rows

func (*MyRowS) Close

func (r *MyRowS) Close() error

Close closes the rows iterator.

func (*MyRowS) Columns

func (r *MyRowS) Columns() []string

Columns returns the names of the columns. The number of columns of the result is inferred from the length of the slice. If a particular column name isn't known, an empty string should be returned for that entry.

func (*MyRowS) Next

func (r *MyRowS) Next(dest []driver.Value) error

Next is called to populate the next row of data into the provided slice. The provided slice will be the same size as the Columns() are wide.

Next should return io.EOF when there are no more rows.

The dest should not be written to outside of Next. Care should be taken when closing Rows not to modify a buffer held in dest.

type MyStmt

type MyStmt struct {
}

MyStmt for sql statement

func (*MyStmt) Close

func (stmt *MyStmt) Close() error

Close implement for stmt

func (*MyStmt) Exec

func (stmt *MyStmt) Exec(args []driver.Value) (driver.Result, error)

Exec exec implement

func (*MyStmt) NumInput

func (stmt *MyStmt) NumInput() int

NumInput row numbers

func (*MyStmt) Query

func (stmt *MyStmt) Query(args []driver.Value) (driver.Rows, error)

Query implement for Query

type MyUser

type MyUser struct {
	Name    string
	Age     int
	Version string
}

MyUser user demo model

Jump to

Keyboard shortcuts

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