diff --git a/_examples/mongo/main.go b/_examples/mongo/main.go deleted file mode 100644 index 72ed1564463dc195c10b2b4ed2e90bd170826b75..0000000000000000000000000000000000000000 --- a/_examples/mongo/main.go +++ /dev/null @@ -1,93 +0,0 @@ -package main - -import ( - "fmt" - "time" - "upper.io/db" - _ "upper.io/db/mongo" -) - -var settings = db.Settings{ - Database: `upperio_tests`, - Host: `127.0.0.1`, -} - -type Birthday struct { - Name string `bson:"name"` - Born time.Time `bson:"born"` -} - -func main() { - - sess, err := db.Open("mongo", settings) - - if err != nil { - fmt.Println("Unable to connect:", err.Error()) - return - } - - defer sess.Close() - - birthdayCollection, err := sess.Collection("birthdays") - - if err != nil { - if err != db.ErrCollectionDoesNotExists { - fmt.Println("Could not use collection:", err.Error()) - return - } - } else { - err = birthdayCollection.Truncate() - - if err != nil { - fmt.Println(err.Error()) - return - } - } - - birthdayCollection.Append(Birthday{ - Name: "Hayao Miyazaki", - Born: time.Date(1941, time.January, 5, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Nobuo Uematsu", - Born: time.Date(1959, time.March, 21, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Hironobu Sakaguchi", - Born: time.Date(1962, time.November, 25, 0, 0, 0, 0, time.UTC), - }) - - var res db.Result - - res = birthdayCollection.Find() - - var birthdays []Birthday - var birthday Birthday - - // Pulling all at once. - err = res.All(&birthdays) - - if err != nil { - panic(err.Error()) - return - } - - for _, birthday = range birthdays { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } - - // Pulling one by one - for { - err = res.Next(&birthday) - if err == nil { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } else if err == db.ErrNoMoreRows { - break - } else { - panic(err.Error()) - } - } - -} diff --git a/_examples/mysql/Makefile b/_examples/mysql/Makefile deleted file mode 100644 index 7c96e037b68f4e4cb1071adfdd1d3ac327b20373..0000000000000000000000000000000000000000 --- a/_examples/mysql/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - cat example.sql | mysql -uupperio -pupperio upperio_tests diff --git a/_examples/mysql/example.sql b/_examples/mysql/example.sql deleted file mode 100644 index b4d9cf76010f557afbaf1426af85acf304248949..0000000000000000000000000000000000000000 --- a/_examples/mysql/example.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE birthdays ( - `name` VARCHAR(50), - `born` DATE -); diff --git a/_examples/mysql/main.go b/_examples/mysql/main.go deleted file mode 100644 index 28036d5d425b7e06594dc04ead060bad31d70eb3..0000000000000000000000000000000000000000 --- a/_examples/mysql/main.go +++ /dev/null @@ -1,93 +0,0 @@ -package main - -import ( - "fmt" - "time" - "upper.io/db" - _ "upper.io/db/mysql" -) - -var settings = db.Settings{ - Database: `upperio_tests`, - Socket: `/var/run/mysqld/mysqld.sock`, - User: `upperio`, - Password: `upperio`, -} - -type Birthday struct { - Name string `field:"name"` - Born time.Time `field:"born"` -} - -func main() { - - sess, err := db.Open("mysql", settings) - - if err != nil { - fmt.Println("Unable to connect:", err.Error()) - return - } - - defer sess.Close() - - birthdayCollection, err := sess.Collection("birthdays") - - if err != nil { - fmt.Println("Could not use collection:", err.Error()) - return - } - - err = birthdayCollection.Truncate() - - if err != nil { - fmt.Println(err.Error()) - return - } - - birthdayCollection.Append(Birthday{ - Name: "Hayao Miyazaki", - Born: time.Date(1941, time.January, 5, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Nobuo Uematsu", - Born: time.Date(1959, time.March, 21, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Hironobu Sakaguchi", - Born: time.Date(1962, time.November, 25, 0, 0, 0, 0, time.UTC), - }) - - var res db.Result - - res = birthdayCollection.Find() - - var birthdays []Birthday - var birthday Birthday - - // Pulling all at once. - err = res.All(&birthdays) - - if err != nil { - panic(err.Error()) - return - } - - for _, birthday = range birthdays { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } - - // Pulling one by one - for { - err = res.Next(&birthday) - if err == nil { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } else if err == db.ErrNoMoreRows { - break - } else { - panic(err.Error()) - } - } - -} diff --git a/_examples/postgresql/Makefile b/_examples/postgresql/Makefile deleted file mode 100644 index cfb21a65da088b8448eb0b129378d7a6f564f2d3..0000000000000000000000000000000000000000 --- a/_examples/postgresql/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - cat example.sql | PGPASSWORD=upperio psql -Uupperio upperio_tests diff --git a/_examples/postgresql/example.sql b/_examples/postgresql/example.sql deleted file mode 100644 index 141018512d1345fa8a60d65e3bc02b93e9fc8f3d..0000000000000000000000000000000000000000 --- a/_examples/postgresql/example.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "birthdays" ( - "name" CHARACTER VARYING(50), - "born" TIMESTAMP -); diff --git a/_examples/postgresql/main.go b/_examples/postgresql/main.go deleted file mode 100644 index 358cc46ef28f8c11263d7d45cbf8c65bfb7426a8..0000000000000000000000000000000000000000 --- a/_examples/postgresql/main.go +++ /dev/null @@ -1,93 +0,0 @@ -package main - -import ( - "fmt" - "time" - "upper.io/db" - _ "upper.io/db/postgresql" -) - -var settings = db.Settings{ - Database: `upperio_tests`, - Socket: `/var/run/postgresql/`, - User: `upperio`, - Password: `upperio`, -} - -type Birthday struct { - Name string `field:"name"` - Born time.Time `field:"born"` -} - -func main() { - - sess, err := db.Open("postgresql", settings) - - if err != nil { - fmt.Println("Unable to connect:", err.Error()) - return - } - - defer sess.Close() - - birthdayCollection, err := sess.Collection("birthdays") - - if err != nil { - fmt.Println("Could not use collection:", err.Error()) - return - } - - err = birthdayCollection.Truncate() - - if err != nil { - fmt.Println(err.Error()) - return - } - - birthdayCollection.Append(Birthday{ - Name: "Hayao Miyazaki", - Born: time.Date(1941, time.January, 5, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Nobuo Uematsu", - Born: time.Date(1959, time.March, 21, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Hironobu Sakaguchi", - Born: time.Date(1962, time.November, 25, 0, 0, 0, 0, time.UTC), - }) - - var res db.Result - - res = birthdayCollection.Find() - - var birthdays []Birthday - var birthday Birthday - - // Pulling all at once. - err = res.All(&birthdays) - - if err != nil { - panic(err.Error()) - return - } - - for _, birthday = range birthdays { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } - - // Pulling one by one - for { - err = res.Next(&birthday) - if err == nil { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } else if err == db.ErrNoMoreRows { - break - } else { - panic(err.Error()) - } - } - -} diff --git a/_examples/sqlite/Makefile b/_examples/sqlite/Makefile deleted file mode 100644 index 03dd503d290287a9be31cc7c2d6057931107d01d..0000000000000000000000000000000000000000 --- a/_examples/sqlite/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - cat example.sql | sqlite3 example.db diff --git a/_examples/sqlite/example.sql b/_examples/sqlite/example.sql deleted file mode 100644 index 947974febf94d99fb7596963fd108514e386cd9e..0000000000000000000000000000000000000000 --- a/_examples/sqlite/example.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE "birthdays" ( - "name" varchar(50) DEFAULT NULL, - "born" varchar(12) DEFAULT NULL, -); diff --git a/_examples/sqlite/main.go b/_examples/sqlite/main.go deleted file mode 100644 index e196ec46233379f922378ece0c487a98e350f6da..0000000000000000000000000000000000000000 --- a/_examples/sqlite/main.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "fmt" - "time" - "upper.io/db" - _ "upper.io/db/sqlite" -) - -var settings = db.Settings{ - Database: `example.db`, -} - -type Birthday struct { - Name string `field:"name"` - Born time.Time `field:"born"` -} - -func main() { - - sess, err := db.Open("sqlite", settings) - - if err != nil { - fmt.Println("Please create the `example.db` sqlite3 database.") - return - } - - defer sess.Close() - - birthdayCollection, err := sess.Collection("birthdays") - - if err != nil { - fmt.Println(err.Error()) - return - } - - err = birthdayCollection.Truncate() - - if err != nil { - fmt.Println(err.Error()) - return - } - - birthdayCollection.Append(Birthday{ - Name: "Hayao Miyazaki", - Born: time.Date(1941, time.January, 5, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Nobuo Uematsu", - Born: time.Date(1959, time.March, 21, 0, 0, 0, 0, time.UTC), - }) - - birthdayCollection.Append(Birthday{ - Name: "Hironobu Sakaguchi", - Born: time.Date(1962, time.November, 25, 0, 0, 0, 0, time.UTC), - }) - - var res db.Result - - res = birthdayCollection.Find() - - var birthdays []Birthday - var birthday Birthday - - // Pulling all at once. - err = res.All(&birthdays) - - if err != nil { - panic(err.Error()) - return - } - - for _, birthday = range birthdays { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } - - // Pulling one by one - for { - err = res.Next(&birthday) - if err == nil { - fmt.Printf("%s was born in %s.\n", birthday.Name, birthday.Born.Format("January 2, 2006")) - } else if err == db.ErrNoMoreRows { - break - } else { - panic(err.Error()) - } - } - -} diff --git a/mongo/_examples/mongo.go b/mongo/_examples/mongo.go deleted file mode 100644 index 46bb6403a2251f2895514aed36e887b4911b9072..0000000000000000000000000000000000000000 --- a/mongo/_examples/mongo.go +++ /dev/null @@ -1,48 +0,0 @@ -package main - -import ( - "fmt" - "upper.io/db" - "upper.io/db/mongo" - "github.com/kr/pretty" -) - -func main() { - sess := mongo.Session(db.DataSource{Host: "10.0.0.11", Database: "gotest"}) - - err := sess.Open() - defer sess.Close() - - if err != nil { - panic(err) - } - - col := sess.Collection("people") - - result := col.FindAll( - db.Relate{ - "lives_in": db.On{ - sess.Collection("places"), - db.Cond{"code_id": "{place_code_id}"}, - }, - }, - db.RelateAll{ - "has_children": db.On{ - sess.Collection("children"), - db.Cond{"parent_id": "{_id}"}, - }, - "has_visited": db.On{ - sess.Collection("visits"), - db.Cond{"person_id": "{_id}"}, - db.Relate{ - "place": db.On{ - sess.Collection("places"), - db.Cond{"_id": "{place_id}"}, - }, - }, - }, - }, - ) - - fmt.Printf("%# v\n", pretty.Formatter(result)) -}