easysql

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

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

Go to latest
Published: Oct 30, 2021 License: MIT Imports: 8 Imported by: 0

README

easysql - developed on 26th Sep.

Easily import string data with SQL in go (for data analysis) with this! Currently uses the MSSQL driver: github.com/denisenkom/go-mssqldb But you can fork it and replace it with another driver (i think)

Simply import it into your go project.

then use as following:

  • login string is the connection i.e "Server=localhost;Database=master;Trusted_Connection=True"
  • query is the SQL query in full

rowcount, output, error := easysql.SQLquery("login string", "query")

  • rowcount = int which tells you how many rows pulled
  • output = []string, the result of the SQL query (including column headers)

You can work with output using type conversion to change items from string to int or float or whatever you want.

Literal example:

package main

import (
	"fmt"

	"github.com/tbal999/easysql"
)

func main() {
	sqlLogin := `Server=localhost;Database=master;Trusted_Connection=True;`

	sqlQuery := `SELECT COLUMN FROM TABLE`

	numberOfRows, result, err := easysql.SQLquery(sqlLogin, sqlQuery)

	if err != nil {
		fmt.Println(err.Error())
	}

	for index := range result {
		fmt.Println(result[index])
	}

	fmt.Printf("Grabbed %d rows", numberOfRows)
}

This library currently can't handle all types - for example datetime - so if you have a DATETIME output in SQL just change it to VARCHAR(255) and it will work. Any format it cannot handle it will let you know by replacing all items in the column to 'CHANGE_TO_VARCHAR'. So then you can just adjust the SQL query slightly.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SQLquery

func SQLquery(access, q string) (int, []string, error)

SQLquery - Submit a SQL username/password/access details (access) and query (q) and receive three outputs: number of rows, a 1D slice of query result, error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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