public_host
4 years ago
4 changed files with 144 additions and 26 deletions
-
22hasaki-gen-crud.js
-
41hasaki-gen-crud/hasaki-gen-crud.js
-
103hasaki-gen-crud/template.go
-
4test.go
@ -1,22 +0,0 @@ |
|||||
|
|
||||
try { |
|
||||
|
|
||||
const vscode = require("vscode") |
|
||||
const fs = require("fs") |
|
||||
|
|
||||
let start = vscode.window.activeTextEditor.document.lineCount |
|
||||
let fileName = vscode.window.activeTextEditor.document.fileName |
|
||||
|
|
||||
console.log(start) |
|
||||
console.log(fileName) |
|
||||
fs.readFile(fileName, function (context) { |
|
||||
|
|
||||
var context_arr = context.split("\n") |
|
||||
console.log(context) |
|
||||
console.log(context_arr[start]) |
|
||||
}) |
|
||||
|
|
||||
} catch (error) { |
|
||||
|
|
||||
console.log(error) |
|
||||
} |
|
@ -0,0 +1,41 @@ |
|||||
|
|
||||
|
try { |
||||
|
|
||||
|
const vscode = require("vscode") |
||||
|
const fs = require("fs") |
||||
|
const axios = require("axios") |
||||
|
|
||||
|
let start = vscode.window.activeTextEditor.selection.start.line |
||||
|
let fileName = vscode.window.activeTextEditor.document.fileName |
||||
|
|
||||
|
console.log(start) |
||||
|
console.log(fileName) |
||||
|
fs.readFile(fileName, 'utf8', (err, data) => { |
||||
|
if (err) throw err; |
||||
|
|
||||
|
|
||||
|
var context_arr = data.split("\n") |
||||
|
|
||||
|
|
||||
|
|
||||
|
let a = context_arr[start].trim(" ") |
||||
|
|
||||
|
console.log(a) |
||||
|
for (; a.indexOf(" ") > 0;) { |
||||
|
a = a.replace(" ", " ") |
||||
|
} |
||||
|
let b = a.split(" ") |
||||
|
if (b[0] != "type" || b[2] != "struct" || b[3] != "{") { |
||||
|
vscode.window.showErrorMessage("找不到结构") |
||||
|
return |
||||
|
} |
||||
|
let struct = b[1] |
||||
|
|
||||
|
axios.get("") |
||||
|
console.log(struct) |
||||
|
}) |
||||
|
|
||||
|
} catch (error) { |
||||
|
|
||||
|
console.log(error) |
||||
|
} |
@ -0,0 +1,103 @@ |
|||||
|
package main |
||||
|
|
||||
|
import ( |
||||
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskdb" |
||||
|
"git.ouxuan.net/hasaki-service/hasaki-sdk/hskgin" |
||||
|
) |
||||
|
|
||||
|
type Temp3A60 struct { |
||||
|
Id int |
||||
|
} |
||||
|
|
||||
|
// ----------------------------temp------------------------------------
|
||||
|
|
||||
|
func (that *Temp3A60) where() (q interface{}, args []interface{}) { |
||||
|
//todo 根据需求修改
|
||||
|
return "`id`=?", []interface{}{ |
||||
|
that.Id, |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
func (that *Temp3A60) Save(isCols ...bool) (err error) { |
||||
|
tmp := Temp3A60{} |
||||
|
whereQuery, whereArgs := that.where() |
||||
|
hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&tmp) |
||||
|
if tmp.Id == 0 { |
||||
|
_, err = hskdb.GetXormAuto().Insert(that) |
||||
|
} else { |
||||
|
if len(isCols) > 0 && isCols[0] { |
||||
|
_, err = hskdb.GetXormAuto().AllCols().Where(whereQuery, whereArgs...).Update(that) |
||||
|
} else { |
||||
|
_, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Update(that) |
||||
|
} |
||||
|
} |
||||
|
return err |
||||
|
} |
||||
|
|
||||
|
func (that *Temp3A60) Load() (err error) { |
||||
|
whereQuery, whereArgs := that.where() |
||||
|
_, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Get(&that) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func (that *Temp3A60) Data() (data []Temp3A60) { |
||||
|
hskdb.GetXormAuto().OrderBy("id desc").Find(&data) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func (that *Temp3A60) PageData(page, pageSize int) (data []Temp3A60, count int64) { |
||||
|
count, _ = hskdb.GetXormAuto().OrderBy("id desc").Limit(pageSize, page*pageSize).FindAndCount(&data) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
func (that *Temp3A60) Delete() (err error) { |
||||
|
whereQuery, whereArgs := that.where() |
||||
|
_, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Delete(&that) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
//该方法请不要放在db文件中
|
||||
|
func InitializationTemp3A60(router *hskgin.GinHelper) { |
||||
|
var authority = func(ctx *hskgin.GinContextHelper) { |
||||
|
//todo 权限控制
|
||||
|
} |
||||
|
|
||||
|
router.Any("/?????/Temp3A60/get", func(ctx *hskgin.GinContextHelper) { |
||||
|
authority(ctx) |
||||
|
req := Temp3A60{} |
||||
|
ctx.Bind(&req) |
||||
|
err := req.Load() |
||||
|
ctx.CheckErrDisplayByError(err) |
||||
|
ctx.DisplayByData(req) |
||||
|
}) |
||||
|
|
||||
|
router.Any("/?????/Temp3A60/save", func(ctx *hskgin.GinContextHelper) { |
||||
|
authority(ctx) |
||||
|
req := Temp3A60{} |
||||
|
ctx.Bind(&req) |
||||
|
err := req.Save() |
||||
|
ctx.CheckErrDisplayByError(err) |
||||
|
err = req.Load() |
||||
|
ctx.CheckErrDisplayByError(err) |
||||
|
ctx.DisplayByData(req) |
||||
|
}) |
||||
|
|
||||
|
router.Any("/?????/Temp3A60/data", func(ctx *hskgin.GinContextHelper) { |
||||
|
authority(ctx) |
||||
|
req := Temp3A60{} |
||||
|
ctx.Bind(&req) |
||||
|
data := req.Data() |
||||
|
ctx.DisplayByData(data) |
||||
|
}) |
||||
|
|
||||
|
router.Any("/?????/Temp3A60/list", func(ctx *hskgin.GinContextHelper) { |
||||
|
authority(ctx) |
||||
|
req := Temp3A60{} |
||||
|
ctx.Bind(&req) |
||||
|
page := ctx.ParamRequired2Page(true) |
||||
|
data, count := req.PageData(page, 10) |
||||
|
ctx.DisplayByPage(data, count) |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
// ----------------------------temp------------------------------------
|
@ -1,4 +0,0 @@ |
|||||
package main |
|
||||
|
|
||||
type Test struct { |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue