41 lines
820 B
Go
41 lines
820 B
Go
package sqlite
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"path/filepath"
|
|
"skapp/pkg/sdk/utils"
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
var u = utils.Utils{}
|
|
|
|
func init() {
|
|
dbPath := filepath.Join(u.CurrentDir(), "test.db")
|
|
fmt.Printf("dbPath => %v\n", dbPath)
|
|
|
|
// 加密
|
|
//dataSourceName := fmt.Sprintf("file:%s?_pragma_key=%s", dbPath, "shikong")
|
|
// 不加密
|
|
dataSourceName := fmt.Sprintf("file:%s?", dbPath)
|
|
db, err := xorm.NewEngine("sqlite3", dataSourceName)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
return
|
|
}
|
|
|
|
type SqliteMaster struct {
|
|
Type string `xorm:"type"`
|
|
Name string `xorm:"name"`
|
|
TableName string `xorm:"tbl_name"`
|
|
RootPage int `xorm:"rootpage"`
|
|
Sql string `xorm:"sql"`
|
|
}
|
|
all := make([]SqliteMaster, 0)
|
|
|
|
_ = db.Table("sqlite_master").Find(&all)
|
|
for _, item := range all {
|
|
fmt.Printf("%+v\n", item)
|
|
}
|
|
}
|