simdb

package module
v0.0.0-...-6ec9a85 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

simdb

Documentation

Overview

simdbrpc.go

Index

Constants

This section is empty.

Variables

View Source
var SepSim = `#-#`
View Source
var SepSimNS = `#-
`
View Source
var Thread t_thread

Functions

func AddBDDir

func AddBDDir(dir string)

func AddIKeyOneByStrKey

func AddIKeyOneByStrKey(tbname, TXT, skey string, val int64) string

Увеличивает значение одной записи целочисленного ключа по строковому

func AddOneTextByStrKey

func AddOneTextByStrKey(tbname, TXT, skey string, ikey int64)

находит запись с таким ключом и добавляет текст туда

func AddString

func AddString(tbname, TXT, skey string, ikey int64)

==============ADD UPDATE==============================================

func ClearTable

func ClearTable(tbname string)

-----------------------------

func DeleteOneBySKey

func DeleteOneBySKey(tbname, skey string) string

удалить одну сроку по строковому ключу

func DeleteTable

func DeleteTable(tbname string)

-----------------------------

func GetGobStructBySKEY

func GetGobStructBySKEY(tbname string, s interface{}, skey string)

func GetJsonStructBySKEY

func GetJsonStructBySKEY(tbname string, s interface{}, skey string)

-----------------------------

func GetStringByKeys

func GetStringByKeys(tbname, skey string, ikey int64) string

func GetStringBySKey

func GetStringBySKey(tbname, skey string) string

----------------------------------------------------------

func GetStringBySKeyToSym

func GetStringBySKeyToSym(tbname, skey, split_sym string) string

----------------------------------------------------------

func GetStructByUID

func GetStructByUID(tbname, uid string, s interface{})

-----------------------------

func GetTBListAsText

func GetTBListAsText() string

-----------------------------

func GetTBListSlice

func GetTBListSlice() []string

func LoadDBFilesFromDir

func LoadDBFilesFromDir(dir string)

func RemoteCall

func RemoteCall(IPP, Method string, args interface{}, resp interface{}) error

func RunTimers

func RunTimers()
func (l *T_TABLE) load_from_json(dirname string) {
	ftbname := server.storpath + dirname + l.Name + ".json"
	fmt.Println("Открываю:" + ftbname)
	var err error
	var data []byte
	data, err = ioutil.ReadFile(ftbname)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	err = json.Unmarshal(data, l)

	if err != nil {
		fmt.Println(err.Error())
	}
	if l.SAVETIMER == 0 {
		l.SAVETIMER = 10
	}
	l.FILE = ftbname
}
func load_all_from_json() {
	files, err := ioutil.ReadDir(server.storpath)
	if err != nil {
		fmt.Println(err.Error())
		return
	} else {
		load_dir_from_json("", &files)
	}
	for _, d := range server.dirs {
		files, err := ioutil.ReadDir(server.storpath + d + "/")
		if err != nil {
			fmt.Println(err.Error())
			//return
		} else {
			load_dir_from_json(d+"/", &files)
		}
	}

}

func load_dir_from_json(dirname string, files *[]os.FileInfo) {
	for _, f := range *files {

		fnm := strings.Split(f.Name(), ".")

		lfnm := len(fnm)
		if lfnm > 1 && !f.IsDir() {
			if fnm[lfnm-1] == "json" {
				//fmt.Println(f.Name())
				on := ""
				if lfnm == 2 {
					on = fnm[0]
				} else {
					for i := 0; i < lfnm-2; i++ {
						on += fnm[i] + "."
					}
					on += fnm[lfnm-2]
				}
				fmt.Println(dirname + on)
				//fmt.Println(dirname + "/" + on)
				Thread.Lock()
				t := get_by_tbname(on)
				t.load_from_json(dirname)
				Thread.Unlock()
			}
		}
	}
}

func SetBackUpDuration

func SetBackUpDuration(tbname string, seconds int) string

func SetSize

func SetSize(tbname, size string)

func SetTimeFormat

func SetTimeFormat(tbname, tformat string)

func StartServer

func StartServer(rpcipp, dbstorpath string) string

func StartSqlite3Server

func StartSqlite3Server(ipport, dbfile, backupfile string) error

IPPORT 127.0.0.1:300 and full paths "./backup/"

func StartServer(ipport, stropath, backuppath string, savepersec int) error {
	log.Println("Start SIMDB server "+ipport, stropath, backuppath)

		server.Sqlite3 = false
		server.savepersec = savepersec
		if stropath != "" {
			server.storpath = stropath
		} else {
			server.storpath = "./"
		}
		if backuppath == "" {
			server.backuppath = "./backup/"

		} else {
			server.backuppath = backuppath
		}
		load_all_from_json()
		server.savetimer = time.NewTicker(time.Second * time.Duration(savepersec))
		go saver()
		if ipport != "" {

			e := nt.StartTCPServer(ipport, msgreciever)
			if e != nil {
				return e
			}
		}

	return nil
}

func StructToGobBySKEY

func StructToGobBySKEY(tbname string, s interface{}, skey string, ikey int64) string

func StructToJsonBySKEY

func StructToJsonBySKEY(tbname string, s interface{}, skey string, ikey int64) string

обновляет json структурой одну запись с таким ключом

func TableConnectRemote

func TableConnectRemote(name, netaddr string) string

подключение сетевой таблицы

func TableGetParamsFromRemoteServer

func TableGetParamsFromRemoteServer(name, servaddr string)

получить параметры таблицы с другого сервера. не доделал. лень...

func TableLoadFromFile

func TableLoadFromFile(name, file string, savetimesec, droptimesec, size int)

загрузить таблицу из файла и ообновить параметры

func TableRegisterAsFile

func TableRegisterAsFile(REMOTEIPP, NAME string)

регистрация локальной таблицы как файла

func TableRegisterAsRemote

func TableRegisterAsRemote(REMOTEIPP, LOCALIPP, NAME string)

регистрация своей таблицы на другом сервере

func TableRegisterFile

func TableRegisterFile(name, file string)

func TableSaveToFile

func TableSaveToFile(name, file string, savetimesec, droptimesec, size int)

сохранить таблицу

func TableUpdateParams

func TableUpdateParams(name, file string, savetimesec, droptimesec, size int)

обновление параметров таблицы

func UpdateAllByStrKey

func UpdateAllByStrKey(tbname, TXT, skey string, ikey int64) string

обновляет все записи с таким ключом. если не найдено то создает новую запись

func UpdateAllStructToJsonBySKEY

func UpdateAllStructToJsonBySKEY(tbname string, s interface{}, skey string, ikey int64) string

обновляет json структурой все записи с таким ключом

func UpdateByIntKey

func UpdateByIntKey(tbname, TXT, sik string)

--Upd BY KEY

func UpdateOneByKeys

func UpdateOneByKeys(tbname, TXT, skey string, ikey int64) string

func UpdateOneBySKey

func UpdateOneBySKey(tbname, TXT, skey string, ikey int64) string

обновляет одну запись с таким ключом.если не найдено то создает новую

Types

type ReTxt

type ReTxt struct {
	Msg string
}

type Req

type Req struct {
	Tbname, TXT, Skey string
	UID, Count        int
	Ikey              int64
}

type ReqExt

type ReqExt struct {
	Tbname, TXT, Skey  string
	UID, Ikey, Count   int
	TimeStart, TimeEnd int64
}

type ReqParams

type ReqParams struct {
	Tbname, File                   string
	Size                           int
	SaveTime, DropTime, BackupTime int
}

type TBF

type TBF struct {
}

func (*TBF) AddIKeyOneByStrKey

func (fp *TBF) AddIKeyOneByStrKey(req Req, res *ReTxt) error

func (*TBF) AddOneTextByStrKey

func (fp *TBF) AddOneTextByStrKey(req Req, res *ReTxt) error

func (*TBF) AddString

func (fp *TBF) AddString(req Req, res *ReTxt) error

==================ADD UPDATE===================================================

func (*TBF) ClearTable

func (fp *TBF) ClearTable(req string, res *ReTxt) error

func (*TBF) DeleteOneByStrKey

func (fp *TBF) DeleteOneByStrKey(req Req, res *ReTxt) error

func (*TBF) GetTable

func (fp *TBF) GetTable(req Req, res *T_RESULT) error

GET

func (*TBF) GetTableBySKey

func (fp *TBF) GetTableBySKey(req Req, res *T_RESULT) error

func (*TBF) GetTableBySKeyFL

func (fp *TBF) GetTableBySKeyFL(req Req, res *T_RESULT) error

func (*TBF) GetTableBySKeyFLYounger

func (fp *TBF) GetTableBySKeyFLYounger(req ReqExt, res *T_RESULT) error

func (*TBF) GetTableFL

func (fp *TBF) GetTableFL(req Req, res *T_RESULT) error

func (*TBF) GetTableFLYounger

func (fp *TBF) GetTableFLYounger(req ReqExt, res *T_RESULT) error

func (*TBF) GetTableList

func (fp *TBF) GetTableList(req Req, res *T_table_list) error

----------------------------

func (*TBF) SetSize

func (fp *TBF) SetSize(req string, res *ReTxt) error

func (*TBF) TableRegisterAsFile

func (fp *TBF) TableRegisterAsFile(req ReqParams, res *ReTxt) error

func (*TBF) TableUpdateParams

func (fp *TBF) TableUpdateParams(req ReqParams, res *ReTxt) error

TOOL

func (*TBF) UpdateAllByStrKey

func (fp *TBF) UpdateAllByStrKey(req Req, res *ReTxt) error

func (*TBF) UpdateOneByStrKey

func (fp *TBF) UpdateOneByStrKey(req Req, res *ReTxt) error

-----------------------------

type T_LSTRING

type T_LSTRING struct {
	TXT       string
	STRKEY    string
	INTKEY    int64
	TIMESTAMP int64
}

type T_RESULT

type T_RESULT struct {
	Str    []T_RSTRING
	CurStr *T_RSTRING
	// contains filtered or unexported fields
}

func GetTable

func GetTable(tbname string, count int) T_RESULT

--------------------------------------------------------------

func GetTableByIKey

func GetTableByIKey(tbname string, key, count int64) T_RESULT

func GetTableByIKeyFL

func GetTableByIKeyFL(tbname, count string, key int64) T_RESULT

--------------------------------------------------------------

func GetTableBySKey

func GetTableBySKey(tbname, skey string, count int) T_RESULT

func (*T_RESULT) GetTable

func (r *T_RESULT) GetTable(tbname string, count int) string

-------------GET TABLE----------------------------------------

func (*T_RESULT) GetTableByIKey

func (r *T_RESULT) GetTableByIKey(tbname string, ikey int64, count int) error

func (*T_RESULT) GetTableBySKey

func (r *T_RESULT) GetTableBySKey(tbname, skey string, count int) string

--------------------------------------------------------------

func (*T_RESULT) GetTableBySKeyFL

func (r *T_RESULT) GetTableBySKeyFL(tbname, skey string, count int) string

--------------------------------------------------------------

func (*T_RESULT) GetTableBySKeyFLYounger

func (r *T_RESULT) GetTableBySKeyFLYounger(tbname, skey string, count int, timenano int64) string

--------------------------------------------------------------

func (*T_RESULT) GetTableFL

func (r *T_RESULT) GetTableFL(tbname string, count int) string

func (*T_RESULT) GetTableFLYounger

func (r *T_RESULT) GetTableFLYounger(tbname string, count int, timenano int64) string

func (*T_RESULT) Next

func (r *T_RESULT) Next() bool

func (*T_RESULT) SortByTimeFirstNew

func (r *T_RESULT) SortByTimeFirstNew()

============================SORT=========================================

func (*T_RESULT) SortByTimeFirstOld

func (r *T_RESULT) SortByTimeFirstOld()

type T_RSTRING

type T_RSTRING struct {
	TIME     string
	TEXT     string
	STRKEY   string
	INTKEY   int64
	TimeNano int64
}
type t_res_string struct {
	UID, IntKey int
	TimeNano    int64
	TIME        string
	TEXT        string
	STRKEY      string
}
func (ts *t_res_string) JsonToStruct(s interface{}) {
	bytes := []byte(ts.TEXT)
	e := json.Unmarshal(bytes, &s)
	if e != nil {
		//fmt.Println(e.Error())
	}
}

func GetOneRowBySkey

func GetOneRowBySkey(tbname, skey string) T_RSTRING

----------------------------------------------------------

type T_TABLE

type T_TABLE struct {
	STRINGS                   []T_LSTRING
	Name                      string
	FILE, BACKUPFILE, NETADDR string
	TIMEFORMAT                string
	COUNT                     int
	SIZE                      int
	START                     int
	//END         int
	CURL int
	//LASTUID                                  int
	SAVETIMER, DROPTIMER, BACKUPTIMER int

	IsRemote bool
	// contains filtered or unexported fields
}

func GetTablePointer

func GetTablePointer(tbname string) *T_TABLE

func (*T_TABLE) AddStringL

func (l *T_TABLE) AddStringL(TXT, skey string, ikey int64)

func (*T_TABLE) DeleteString

func (l *T_TABLE) DeleteString(strnum int)

func (*T_TABLE) MoveToBackUp

func (l *T_TABLE) MoveToBackUp()

====SERVICES==========================================================

func (*T_TABLE) Resize

func (l *T_TABLE) Resize(nsize int)

type T_table_info

type T_table_info struct {
	Name   string
	Count  int
	Remote bool
}

type T_table_list

type T_table_list struct {
	TABLE []T_table_info
}

func GetTBList

func GetTBList() T_table_list

Jump to

Keyboard shortcuts

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