redisql

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

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

Go to latest
Published: Mar 16, 2020 License: MIT Imports: 8 Imported by: 0

README

redisql

##support Query Cmds

  • use databasename
  • show databases
  • show tables
  • show index from tablename
  • create database databasename
  • create table tablename(field1 type1, ...);
  • create index indexname on tablename(field);
  • insert into tablename(field1 ...) values(value1 ...)
  • select
  • Limit
  • Other Comming soon

##how to use ###make

//build parse sql lib 'libparse.so' 
> cd redisql/redisql_parse/yacc
> make

//copy 'libparse.so' to redisql_cli or your project
//build client, need 'libparse.so'.
> cd redisql/redisql_cli
> go build

###client ###call by golang

redisql.Connect("127.0.0.1", "6379", "", "tcp", 5, 120)
redisql.Selectdb(0)
res, err := redisql.Query("show databases")
if err != nil {
	fmt.Println(err)
	return
}
...

Documentation

Index

Constants

View Source
const (
	REDISQL_USE             = iota //use databasename;
	REDISQL_SHOW_DATABASES         //show databases;
	REDISQL_SHOW_TABLES            //show tables;
	REDISQL_SHOW_INDEX             //show index from tablename;
	REDISQL_DESC                   //desc tablename;
	REDISQL_CREATE_DATABASE        //create database databasename;
	REDISQL_CREATE_TABLE           //create table tbname(field1,type1...);
	REDISQL_CREATE_INDEX           //create index indexname on tablename(fieldname);
	REDISQL_INSERT                 //insert into tablename(field1...) values(value1...);
	REDISQL_SELECT                 //select field1... from table1... where case1... limit start end
	REDISQL_UPDATE                 //update tablename set field1=value1 where case1...
	REDISQL_DELETE                 //delete from tablename where case1...
	REDISQL_DROP_DATABASE          //drop database databasename
	REDISQL_DROP_TABLE             //drop table tablename
	REDISQL_EXIT                   //exit
	REDISQL_HELP                   //help
	REDISQL_EMPTY
)
View Source
const (
	QUERY_OK_0 = "Query OK, 0 rows affected"
	QUERY_OK_1 = "Query OK, 1 row affected"
)
View Source
const (
	REDISQL_TYPE_NUMBER = "NUMBER"
	REDISQL_TYPE_STRING = "STRING"
	REDISQL_TYPE_DATE   = "DATE"
)

data type design number include INT FLOAT DOUBLE string include CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT、ENUM date include DATA DATATIME ignore enum or set number and date will support range query string will support fuzzy search

View Source
const (
	REDISQL_PRIORITY_GREATER = 1
	REDISQL_PRIORITY_EQUAL   = 0
	REDISQL_PRIORITY_LESS    = -1
	REDISQL_PRIORITY_ERROR   = -2
)
View Source
const (
	REDISQL_DATABASES     = "databases"                     //hset databases lnkgift 1
	REDISQL_CONDITION_SN  = "%s.condition.sn"               //query condition sn
	REDISQL_TABLES        = "%s.tables"                     //hset lnkgift.tables user 1
	REDISQL_COUNT         = "%s.tables.count"               //hset lnkgift.tables.count user 1
	REDISQL_FIELDS        = "%s.%s.fields"                  //hset lnkgift.user.fields name string
	REDISQL_UNIQUE        = "%s.%s.unique"                  //sadd lnkgift.user.unique name
	REDISQL_INDEXS        = "%s.%s.indexs"                  //hset lnkgift.user.indexs index_name [name]
	REDISQL_DATAS         = "%s.%s.data.%s"                 //hset lnkgift.user.data.1 name qianno
	REDISQL_INDEX_DATAS   = "%s.%s.index.%s"                //string: sadd lnkgift.user.index.name.qianno 1 or number,date: zadd lnkgift.user.index.age 26 1
	REDISQL_TMP_CONDITION = "%s.%s.tmp.condition.%s"        //sadd lnkgift.user.tmp.condition.1 1 2 3 4
	REDISQL_TMP_CARTESIAN = "%s.tmp.condition.cartesian.%s" //hset lnkgift.tmp.condition.descartes.1 a_1_b_2_c_1_
)

redis store key design

Variables

View Source
var (
	CompareSign = []string{"=", "!=", ">", ">=", "<", "<=", "LIKE"}
	Opertion    = []string{"(", ")", "AND", "OR", "#"}
)

Functions

func ChangeDatabase

func ChangeDatabase(db string) error

func Compare

func Compare(oldsign, newsign string) int

func Connect

func Connect(server, port, password, protocol string, idleMax, idleTimeput int)

func CreateDatabase

func CreateDatabase(dbname string) error

func GetDatabases

func GetDatabases() ([]string, float64, error)

func GetDbInfo

func GetDbInfo() (int, string)

func GetTableInfo

func GetTableInfo(tablename string) ([][]string, float64, error)

func GetTables

func GetTables() ([]string, float64, error)

func Selectdb

func Selectdb(db int)

func ToArray

func ToArray(reply interface{}) [][]string

Types

type Inner

type Inner struct {
	Inner string
	Alias string
	On    string
	And   string
	Or    string
}

how to use eg: FIELDS("a.name, a.age, a.city, b.userid, b.operate, b.detail, b.data")

.FROM("user, log").ALIAS("a, b")
.WHERE(a.id = b.userid AND a.age = 24) OR (b.operate = "login").SELECT()

type Insert

type Insert struct {
	Into   string
	Fields []string
	Values []interface{}
}

func INTO

func INTO(tablename string) *Insert

func (*Insert) FIELDS

func (ist *Insert) FIELDS(fields ...string) *Insert

func (*Insert) INSERT

func (ist *Insert) INSERT() error

func (*Insert) VALUES

func (ist *Insert) VALUES(values ...interface{}) *Insert

type Left

type Left struct {
	Left  string
	Alias string
	On    string
	And   string
	Or    string
}

type QueryRes

type QueryRes struct {
	Type      int
	ParseTime float64
	QueryTime float64
	Result    interface{}
}

func Query

func Query(sql string) (*QueryRes, error)

type RedisConnect

type RedisConnect struct {
	// contains filtered or unexported fields
}
var (
	DB RedisConnect
)
type Right struct {
	Right string
	Alias string
	On    string
	And   string
	Or    string
}

type Select

type Select struct {
	Froms  SltTable   //query table must have an alias
	Fields []SltField //query field must like tablealias.fieldname, it can have an alias also.
	Where  []string
	Top    int
	Limit  []int
}

func FROM

func FROM(tables ...string) *Select

func (*Select) FIELDS

func (slt *Select) FIELDS(fields ...string) *Select

func (*Select) LIMIT

func (slt *Select) LIMIT(start, end int) *Select

func (*Select) SELECT

func (slt *Select) SELECT() ([][]string, error)

func (*Select) TOP

func (slt *Select) TOP(top int) *Select

func (*Select) WHERE

func (slt *Select) WHERE(condition string) *Select

type SltField

type SltField struct {
	TableAlias string
	Name       string
	Alias      string
}

type SltTable

type SltTable map[string]string

type Table

type Table struct {
	Name   string
	Fields []string
	Types  []string
}

func TABLE

func TABLE(tablename string) *Table

func (*Table) CREATE

func (tab *Table) CREATE() error

func (*Table) FIELDS

func (tab *Table) FIELDS(fields ...string) *Table

func (*Table) INDEX

func (tab *Table) INDEX() error

func (*Table) TYPES

func (tab *Table) TYPES(types ...string) *Table

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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