Browse Source

test-code

Soe Thu 5 years ago
parent
commit
43b6f11cb5
2 changed files with 64 additions and 0 deletions
  1. 32 0
      postgres_test.go
  2. 32 0
      sqlite_test.go

+ 32 - 0
postgres_test.go

@@ -0,0 +1,32 @@
+package db
+
+import (
+	"db"
+	"fmt"
+)
+func test struct{
+}
+func (test) TestPostgres() {
+	p := "host=localhost user=forwardtest password=forwardtest dbname=forward sslmode=disable"
+	dd, err := db.Open("postgres", p)
+	if err != nil {
+		fmt.Println("Error", err.Error())
+	}
+	fmt.Println(dd.Hello())
+	dd.Orm().LogMode(true)
+	dd.Orm().AutoMigrate(&MyTables{})
+	meta, err := dd.GetMeta("my_tables")
+	if err != nil {
+		fmt.Println("Erro Meta ", err.Error())
+	}
+	if myInfo, ok := meta.([]db.PostgresTableInfo); ok {
+		for _, info := range myInfo {
+			fmt.Println("Info", info)
+		}
+	}
+	v, err := dd.GetTables()
+	if err != nil {
+		fmt.Println("Erro Table ", err.Error())
+	}
+	fmt.Println(fmt.Printf("Tables %s", v))
+}

+ 32 - 0
sqlite_test.go

@@ -0,0 +1,32 @@
+package db
+
+import (
+	"db"
+	"fmt"
+)
+
+func (test) TestSqlite() {
+	dd, err := db.Open("sqlite3", "./my.db")
+	if err != nil {
+		fmt.Println("Error", err.Error())
+	}
+	fmt.Println(dd.Hello())
+	dd.Orm().LogMode(true)
+	dd.Orm().AutoMigrate(&MyTables{})
+	dd.Orm().Exec("PRAGMA foreign_keys = ON;")
+	dd.Orm().SingularTable(true)
+	meta, err := dd.GetMeta("my_tables")
+	if err != nil {
+		fmt.Println("Erro Meta ", err.Error())
+	}
+	if m, ok := meta.([]db.TableInfo); ok {
+		for _, mv := range m {
+			fmt.Println("INFO", mv)
+		}
+	}
+	v, err := dd.GetTables()
+	if err != nil {
+		fmt.Println("Erro Table ", err.Error())
+	}
+	fmt.Println(fmt.Printf("Tables %s", v))
+}