deprecated funcs fix
This commit is contained in:
parent
c362b6bc33
commit
fb6955465a
24
db.go
24
db.go
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -402,16 +401,13 @@ func (t *TableInfo) DeleteColumn(name string) error {
|
||||
}
|
||||
|
||||
func (db *Db) ImportSchema(filename string) {
|
||||
jsonFile, err := os.Open(filename)
|
||||
byteValue, _ := os.ReadFile(filename)
|
||||
|
||||
var jsonSource []TableInfo
|
||||
err := json.Unmarshal([]byte(byteValue), &jsonSource)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
var jsonSource []TableInfo
|
||||
json.Unmarshal([]byte(byteValue), &jsonSource)
|
||||
for _, ti := range jsonSource {
|
||||
ti.db = db
|
||||
err = db.CreateTable(ti)
|
||||
@ -422,19 +418,13 @@ func (db *Db) ImportSchema(filename string) {
|
||||
}
|
||||
|
||||
func (db *Db) ClearImportSchema(filename string) {
|
||||
jsonFile, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
byteValue, _ := os.ReadFile(filename)
|
||||
|
||||
var jsonSource []TableInfo
|
||||
json.Unmarshal([]byte(byteValue), &jsonSource)
|
||||
for _, ti := range jsonSource {
|
||||
ti.db = db
|
||||
err = ti.DeleteTable()
|
||||
err := ti.DeleteTable()
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
@ -600,7 +590,7 @@ func (db *Db) SaveSchema(generatedFilename string) error {
|
||||
}
|
||||
// file, _ := json.Marshal(schema)
|
||||
file, _ := json.MarshalIndent(schema, "", " ")
|
||||
_ = ioutil.WriteFile(generatedFilename, file, 0644)
|
||||
_ = os.WriteFile(generatedFilename, file, 0644)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
16
my_test.go
16
my_test.go
@ -3,7 +3,6 @@ package sqldb
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
@ -12,18 +11,12 @@ func TestMyCreateTable(t *testing.T) {
|
||||
db := Open("mysql", "test:test@tcp(127.0.0.1:3306)/test?parseTime=true")
|
||||
defer db.Close()
|
||||
|
||||
jsonFile, err := os.Open("test_table.json")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
byteValue, _ := os.ReadFile("test_table.json")
|
||||
|
||||
var jsonSource TableInfo
|
||||
json.Unmarshal([]byte(byteValue), &jsonSource)
|
||||
|
||||
err = db.CreateTable(jsonSource)
|
||||
err := db.CreateTable(jsonSource)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
@ -88,10 +81,9 @@ func TestMyInsert(t *testing.T) {
|
||||
if len(jsonStringOld) == len(jsonStringNew) {
|
||||
t.Errorf("Error row not created")
|
||||
}
|
||||
jsonFile, err := os.Open("insert.json")
|
||||
defer jsonFile.Close()
|
||||
|
||||
var result map[string]interface{}
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
byteValue, _ := os.ReadFile("insert.json")
|
||||
json.Unmarshal(byteValue, &result)
|
||||
}
|
||||
|
||||
|
15
pg_test.go
15
pg_test.go
@ -3,7 +3,6 @@ package sqldb
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
@ -12,18 +11,12 @@ func TestPgCreateTable(t *testing.T) {
|
||||
db := Open("postgres", "host=127.0.0.1 port=5432 user=test password=test dbname=test sslmode=disable")
|
||||
defer db.Close()
|
||||
|
||||
jsonFile, err := os.Open("test_table.json")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
byteValue, _ := os.ReadFile("test_table.json")
|
||||
|
||||
var jsonSource TableInfo
|
||||
json.Unmarshal([]byte(byteValue), &jsonSource)
|
||||
|
||||
err = db.CreateTable(jsonSource)
|
||||
err := db.CreateTable(jsonSource)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
@ -88,10 +81,8 @@ func TestPgInsert(t *testing.T) {
|
||||
if len(jsonStringOld) == len(jsonStringNew) {
|
||||
t.Errorf("Error row not created")
|
||||
}
|
||||
jsonFile, err := os.Open("insert.json")
|
||||
defer jsonFile.Close()
|
||||
var result map[string]interface{}
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
byteValue, _ := os.ReadFile("insert.json")
|
||||
json.Unmarshal(byteValue, &result)
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
"id":"integer",
|
||||
"name":"varchar(255)|comment",
|
||||
"description":"varchar(1000)",
|
||||
"startdate":"timestamp",
|
||||
"enddate":"timestamp",
|
||||
"startdate":"date",
|
||||
"endtime":"timestamp",
|
||||
"latitude":"float|map",
|
||||
"longitude":"float|map",
|
||||
"intvalue":"integer",
|
||||
|
Loading…
Reference in New Issue
Block a user