Exemple #1
0
// first init for table,
// create data and pk directories and default files.
func (t *Table) firstInit() (e error) {
	// create directory
	e = os.MkdirAll(t.directory, os.ModePerm)
	if e != nil {
		return
	}

	// init data chunk
	dir := path.Join(t.directory, "_data")
	if t.Chunk, e = col.NewChunk(dir, "data", ".dat", 1000, t.Object.DataType); e != nil {
		return
	}

	// init pk
	dir = path.Join(t.directory, "_pk")
	if t.Pk, e = col.NewPk(dir, t.Object.PkAuto); e != nil {
		return
	}

	return
}
Exemple #2
0
// init table.
// if first run, create chunk and pk.
// otherwise, read chunk data and pk data.
func (t *Table) init() (e error) {
	if !com.IsDir(t.directory) {
		e = t.firstInit()
		return
	}

	// read pk file
	dir := path.Join(t.directory, "_pk")
	if t.Pk, e = col.NewPk(dir, t.Object.PkAuto); e != nil {
		return
	}

	// read chunk file
	dir = path.Join(t.directory, "_data")
	if t.Chunk, e = col.NewChunk(dir, "data", ".dat", 1000, t.Object.DataType); e != nil {
		return
	}

	// read last chunk as default
	e = t.Chunk.ReadCursorFile(t.Pk.GetLastCursor(), true)

	return
}