Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
feat: data structure and core (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar authored Sep 1, 2023
1 parent 4b02423 commit 8b0f4de
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 131 deletions.
26 changes: 26 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### Todo
- [ ] Get Sets Name
- [ ] Drop Set
- [ ] Clean Set
- [ ] Get Elements of a set
- [ ] Count elements of a set
- [ ] Remove Element from a set
- [ ] Update Element from a set
- [ ] Get All Keys
- [ ] Get All Values
- [ ] Create Snapshot
- [ ] Create schedule Snapshot
- [ ] End Snapshot
- [ ] Find List of Elements from a set
- [ ] Sort With Limit And Offset
- [ ] regex search
- [ ] Update list of elements from a set
- [ ] Remove list of elements from a set
- [ ] handles foreach operation on a set
- [ ] HAVE QUERY => T/F


### In Progress


### ✓ Done
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"os"

"github.com/zurvan-lab/TimeTraceDB/src"
"github.com/zurvan-lab/TimeTraceDB/core/database"
)

func main() {
database := src.CreateDataBase(os.Args[1])
database := database.CreateDataBase(os.Args[0])
database.InitSocket()
database.InitUsers()
}
8 changes: 6 additions & 2 deletions src/config.go → config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src
package config

import (
"os"
Expand Down Expand Up @@ -40,7 +40,11 @@ func createConfig() *Config {
return &Config{}
}

func ReadConfigFile(path string) *Config {
func (c Config) BasicCheck() error {
return nil
}

func LoadFromFile(path string) *Config {
file, err := os.Open(path)
if err != nil {
log.Error("Can not open the config file", "error: ", err)
Expand Down
13 changes: 8 additions & 5 deletions src/database.go → core/database/database.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package src
package database

import (
"net"
"os"

"github.com/zurvan-lab/TimeTraceDB/config"
"github.com/zurvan-lab/TimeTraceDB/core"
)

type Database struct {
Sets Sets
Config Config
Config config.Config
socket net.Listener
Users Users
Users core.Users
}

func CreateDataBase(path string) *Database {
return &Database{
Sets: *NewSets(),
Config: *ReadConfigFile(path),
Config: *config.LoadFromFile(path),
}
}

Expand All @@ -28,7 +31,7 @@ func (db *Database) InitSocket() {
}

func (db *Database) InitUsers() {
users := CreateUsers()
users := core.CreateUsers()
db.Users = *users
cmds := []string{"all"}
users.NewUser(db.Config.FirstUser.Name, db.Config.FirstUser.Token, cmds)
Expand Down
12 changes: 12 additions & 0 deletions core/database/element.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package database

import "time"

type Element struct {
value string
time time.Time
}

func NewElement(v string) Element {
return Element{value: v, time: time.Now()}
}
21 changes: 21 additions & 0 deletions core/database/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package database

type set map[string]SubSet

type Sets map[string]set

func NewSets() *Sets {
return &Sets{}
}

func newSet() *set {
return &set{}
}

func (s *Sets) AddSet(name string) {
(*s)[name] = *newSet()
}

func (s set) AddSubSet(name string) {
(s)[name] = *NewSubSet()
}
17 changes: 17 additions & 0 deletions core/database/subSets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package database

type SubSets map[string]SubSet
type SubSet []Element

func NewSubSets() SubSets {
return SubSets{}
}

func NewSubSet() *SubSet {
return &SubSet{}
}

func (db *Database) PushElement(s string, sb string, e Element) {
r := db.Sets[s][sb]
db.Sets[s][sb] = append(r, e)
}
1 change: 1 addition & 0 deletions core/execution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package core
2 changes: 1 addition & 1 deletion src/user.go → core/user.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package src
package core

import (
"github.com/zurvan-lab/TimeTraceDB/utils"
Expand Down
2 changes: 2 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func addFields(event *zerolog.Event, keyvals ...interface{}) *zerolog.Event {
event.Stringer(key, v)
case []byte:
event.Str(key, fmt.Sprintf("%v", hex.EncodeToString(v)))
case error:
event.AnErr(key, v)
default:
event.Any(key, v)
}
Expand Down
9 changes: 0 additions & 9 deletions src/connection.go

This file was deleted.

20 changes: 0 additions & 20 deletions src/element.go

This file was deleted.

92 changes: 0 additions & 92 deletions src/set.go

This file was deleted.

8 changes: 8 additions & 0 deletions utils/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ func GenerateRandomNumber(min, max int) (int, error) {

return int(n.Int64()) + min, nil
}

func BytesToString(data []byte) string {
return string(data)
}

func StringToBytes(s string) []byte {
return []byte(s)
}

0 comments on commit 8b0f4de

Please sign in to comment.