// NewSTable function description : 新建数据库表 // params : // return : func NewSTable(tablename, pathname string, fieldsinfos []FieldMeta, logger *utils.Log4FE) *STable { this := &STable{MaxCount: 0, Logger: logger, Pathname: pathname, Tablename: tablename, FieldInfos: fieldsinfos, Fields: make(map[string]FieldMeta)} if utils.IsExist(pathname + "/" + tablename + TB_DTL_TAIL) { this.Logger.Error("[ERROR] STable[%v] is exist", tablename) return nil } for _, field := range fieldsinfos { if _, ok := this.Fields[field.Fieldname]; ok { this.Logger.Error("[ERROR] Field[%v] exist", field.Fieldname) return nil } this.Fields[field.Fieldname] = field } //创建表的索引,使用b+树索引 if err := this.createIndex(); err != nil { this.Logger.Error("[ERROR] createIndex %v", err) return nil } //创建detail文件 if err := this.createDetail(); err != nil { this.Logger.Error("[ERROR] createDetail %v", err) return nil } this.Logger.Info("[INFO] STable[%v] Create ok", tablename) return this }
//NewSTable(tablename, pathname string, fieldsinfo map[string]FieldMeta, logger *utils.Log4FE) *STable // NewSDatabase function description : 新建数据库 // params : // return : func NewSDatabase(dbname, dbpath string, logger *utils.Log4FE) *SDatabase { this := &SDatabase{Logger: logger, Pathname: dbpath, Name: dbname} this.Fullname = dbpath + "/" + dbname if utils.IsExist(this.Fullname) { this.Logger.Error("[ERROR] SDatabase[%v] is exist", dbname) return nil } os.MkdirAll(this.Fullname, 0777) if err := this.initDatabase(); err != nil { return this } this.Logger.Info("[INFO] SDatabase[%v] Create ok", dbname) return this }