public_host 4 years ago
parent
commit
d268ed6546
  1. 60
      hasaki-gen-crud/hasaki-gen-crud.js
  2. 4
      hasaki-gen-crud/template.go
  3. 5
      test.go

60
hasaki-gen-crud/hasaki-gen-crud.js

@ -3,7 +3,6 @@ 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
@ -25,14 +24,67 @@ try {
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)
var stack = ['{']
var endLine = 0
var endChar = 0
for (var i = start + 1; i < context_arr.length; i++) {
for (let k = 0; k < context_arr[i].length; k++) {
const element = context_arr[i][k];
if (element == '{') {
stack.push('{')
}
if (element == '}') {
stack.pop()
}
if (stack.length == 0) {
endLine = i
endChar = k
break
}
}
}
if (endLine < start) {
vscode.window.showErrorMessage("结构异常")
return
}
let endPosition = vscode.Position(endLine, endChar)
axios({
method: 'get',
url: 'http://git.ouxuan.net/3136352472/vscode-helper-js/raw/branch/master/hasaki-gen-crud/template.go',
responseType: 'text'
}).then(res => {
console.log("123")
let text = "" + res['data']
let tmp = text.split("// ----------------------------temp------------------------------------")
text = tmp[1]
text = text.replace(/Temp3A60/g, struct)
console.log(text)
vscode.window.activeTextEditor.edit(function (textEditorEdit: vscode.TextEditorEdit) {
textEditorEdit.insert(
endPosition,
text,
)
})
// vscode.window.showErrorMessage(res)
}).catch(error => {
vscode.window.showErrorMessage(`err:${error.message}`)
})
})
} catch (error) {

4
hasaki-gen-crud/template.go

@ -18,14 +18,14 @@ func (that *Temp3A60) where() (q interface{}, args []interface{}) {
}
}
func (that *Temp3A60) Save(isCols ...bool) (err error) {
func (that *Temp3A60) Save(isAllCols ...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] {
if len(isAllCols) > 0 && isAllCols[0] {
_, err = hskdb.GetXormAuto().AllCols().Where(whereQuery, whereArgs...).Update(that)
} else {
_, err = hskdb.GetXormAuto().Where(whereQuery, whereArgs...).Update(that)

5
test.go

@ -0,0 +1,5 @@
package main
type MyTestr struct {
Id int
}
Loading…
Cancel
Save