예제 #1
0
func main() {

	db := mockdb.NewMockDB("backup.json", 5)

	/*
		id1 := db.Add("users", User{1, "Scott Cagno", "*****@*****.**", true})
		fmt.Printf("Added user with id: %q\n", id1)

		id2 := db.Add("users", User{2, "Kayla Cagno", "*****@*****.**", false})
		fmt.Printf("Added user with id: %q\n", id2)

		id3 := db.Add("users", User{3, "Greg Pechiro", "*****@*****.**", true})
		fmt.Printf("Added user with id: %q\n", id3)

		id4 := db.Add("users", User{4, "Rosalie Pechiro", "*****@*****.**", false})
		fmt.Printf("Added user with id: %q\n", id4)

		id5 := db.Add("users", User{5, "Gabe Witmer", "*****@*****.**", true})
		fmt.Printf("Added user with id: %q\n", id5)
	*/

	/*
		var user User
		id := "fcf06596-297a-46ca-a09f-e32b2fae6d59"
		db.GetAs("users", id, &user)
		fmt.Printf("Got user with id %q from db: %+v...\n", id, user)

		fmt.Printf("Modifying user...")
		user.Name = "Mario Mario"
		db.Set("users", id, user)
	*/

	var user []User
	n, ok := db.QueryAll("users", map[string]interface{}{"Id": 5, "Active": true}, &user)
	if !ok {
		fmt.Println("Woops, couldn't find user!!!")
	} else {
		fmt.Printf("Found %d users: %+v\n", n, user)
	}

	fmt.Println("Sleeping for 10 seconds...")
	time.Sleep(time.Duration(10) * time.Second)
}
예제 #2
0
파일: db.go 프로젝트: gabewitmer/go-cns
func init() {
	db = mockdb.NewMockDB("backup.json", 5)
	/*db.Set("user", "one", User{
		Id:       "one",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "employee",
		Active:   true,
	})
	db.Set("user", "one", User{
		Id:       "two",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "employee",
		Active:   true,
	})
	db.Set("user", "three", User{
		Id:       "three",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "employee",
		Active:   true,
	})
	db.Set("user", "four", User{
		Id:       "four",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "company",
		Active:   true,
	})
	db.Set("user", "five", User{
		Id:       "five",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "company",
		Active:   true,
	})
	db.Set("user", "six", User{
		Id:       "six",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "company",
		Active:   true,
	})
	db.Set("user", "seven", User{
		Id:       "seven",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "driver",
		Active:   true,
	})
	db.Set("user", "eight", User{
		Id:       "eight",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "driver",
		Active:   true,
	})
	db.Set("user", "nine", User{
		Id:       "nine",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "driver",
		Active:   true,
	})
	db.Set("user", "ten", User{
		Id:       "ten",
		Email:    "*****@*****.**",
		Password: "******",
		Role:     "admin",
		Active:   true,
	})
	db.Set("employee", "one", Employee{
		Id:        "one",
		FirstName: "John",
		LastName:  "Smith",
		Street:    "1313 Mocking Bird Lane",
		City:      "Lancaster",
		State:     "PA",
		Zip:       "17603",
		Email:     "*****@*****.**",
		UserId:    "one",
	})
	db.Set("employee", "two", Employee{
		Id:        "two",
		FirstName: "Jone",
		LastName:  "Doe",
		Street:    "13 Crutfield dr",
		City:      "Lancaster",
		State:     "PA",
		Zip:       "17603",
		Email:     "*****@*****.**",
		UserId:    "two",
	})
	db.Set("employee", "two", Employee{
		Id:        "three",
		FirstName: "Sam",
		LastName:  "Sparks",
		Street:    "1562 Willoe Road",
		City:      "Lancaster",
		State:     "PA",
		Zip:       "17603",
		Email:     "*****@*****.**",
		UserId:    "three",
	})

	db.Set("employee", "three", Employee{
		Id:        "four",
		FirstName: "Admin",
		LastName:  "Admin",
		Street:    "1 Admin Road",
		City:      "Lancaster",
		State:     "PA",
		Zip:       "17603",
		Email:     "*****@*****.**",
		UserId:    "ten",
	})
	db.Set("company", "one", Company{
		Id:             "one",
		Name:           "Company One",
		Street:         "1 Company drive",
		City:           "Lititz",
		State:          "PA",
		Zip:            "17545",
		Slug:           "company-one",
		AgeRequirement: 18,
		Logo:           false,
		Feature:        true,
		UserId:         "four",
	})
	db.Set("company", "two", Company{
		Id:             "two",
		Name:           "Company Two",
		Street:         "2 Company drive",
		City:           "Lancaster",
		State:          "PA",
		Zip:            "17603",
		Slug:           "company-two",
		AgeRequirement: 21,
		Logo:           false,
		Feature:        true,
		UserId:         "five",
	})
	db.Set("company", "three", Company{
		Id:             "three",
		Name:           "Company Three",
		Street:         "3 Company drive",
		City:           "Ephrata",
		State:          "PA",
		Zip:            "17543",
		Slug:           "company-three",
		AgeRequirement: 16,
		Logo:           false,
		Feature:        false,
		UserId:         "six",
	})
	db.Set("driver", "one", Driver{
		Id:        "one",
		FirstName: "Greg",
		LastName:  "Pechiro",
		Street:    "21 Quaker Hills Rd",
		City:      "Lancaster",
		State:     "PA",
		Zip:       "17603",
		Email:     "*****@*****.**",
		DOB:       0,
		Status:    0,
		UserId:    "seven",
		CompanyId: "one",
	})
	db.Set("driver", "two", Driver{
		Id:        "two",
		FirstName: "Scotty",
		LastName:  "Cagno",
		Street:    "128 Pleasant View Dr",
		City:      "Lititz",
		State:     "PA",
		Zip:       "17543",
		Email:     "*****@*****.**",
		DOB:       0,
		Status:    0,
		UserId:    "eight",
		CompanyId: "two",
	})
	db.Set("driver", "three", Driver{
		Id:        "three",
		FirstName: "Gabe",
		LastName:  "Witmer",
		Street:    "2 Industrial Dr",
		City:      "Ephrata",
		State:     "PA",
		Zip:       "17543",
		Email:     "*****@*****.**",
		DOB:       0,
		Status:    0,
		UserId:    "nine",
		CompanyId: "three",
	})*/

}
예제 #3
0
파일: db.go 프로젝트: gregpechiro/cns
func init() {
	db = mockdb.NewMockDB("backup.json", 5)
}
예제 #4
0
	"os"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"time"

	"github.com/cagnosolutions/dbdb"
	"github.com/cagnosolutions/mockdb"
	"github.com/cagnosolutions/webc"
	"github.com/cagnosolutions/webc/tmpl"
)

var rpc = dbdb.NewClient()
var ts = tmpl.NewTemplateStore(true)
var config = mockdb.NewMockDB("config.json", 5)

func main() {
	mux := webc.NewMux("CTIXID", (webc.HOUR / 2))

	// db managment
	mux.Get("/test", Test)
	mux.Get("/", Root)
	mux.Post("/connection", AddConnection)
	mux.Post("/connection/save", SaveConnection)
	mux.Post("/connection/:db/del", DelConnection)

	mux.Get("/connect/:db", Connect)
	mux.Get("/disconnect", Disconnect)

	mux.Get("/export", ExportDB)