-
Notifications
You must be signed in to change notification settings - Fork 5
/
gosql.js
129 lines (126 loc) · 6.58 KB
/
gosql.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const getFileNameAndExtension = ({filePath}) => {
let path;
try {
path = require('path');
} catch (error) {
console.error("Error importing module:", error);
return null;
}
const pathInfo = path.parse(filePath);
console.log(pathInfo);
return {
extension: pathInfo.ext,
fileName: pathInfo.name,
fileFolder: pathInfo.dir,
};
};
module.exports = {
namespace: "GoSqlx",
commands: [
{
name: "Generate CreateFunc for an input model struct",
template: `Task: Given a Go struct with properly defined database tags, generate the "Create" function code. This function should take an instance of input struct and insert it into the database.\n
The input model struct is:\n
{selection}\n
Constraints:\n
- Use the sqlx for MySQL and Squirrel libraries for database handling and query building respectively. Dont generate the database connection code.
- Assume that string constants for the tablename and column names are available in a package called "spec". Dont use any hardcoded strings.
- Use "ctx context.Context" as the first argument to the function. Use appropriate context methods from the packages.
- Each function should appropriately handle any errors encountered during the database operation.
- Write the function as a method on a Datalayer struct as: "type DL struct { db *sqlx.DB}"
- Dont add any logging. Add appropriate comments.`,
responseHandler: {
func: "writeFile",
args: {
filePath: "user.dlFileName",
},
},
},
{
name: "Generate ReadFunc for an input model struct",
template: `Task: Given a Go struct with properly defined database tags, generate the "Read" function code. This function should take an id as input and return the database entry.\n
The input model struct is:\n
{selection}\n
Constraints:\n
- Use the sqlx for MySQL and Squirrel libraries for database handling and query building respectively. Dont generate the database connection code.
- Assume that string constants for the tablename and column names are available in a package called "spec". Dont use any hardcoded strings.
- Use "ctx context.Context" as the first argument to the function. Use appropriate context methods from the packages.
- Each function should appropriately handle any errors encountered during the database operation.
- Write the function as a method on a Datalayer struct as: "type DL struct { db *sqlx.DB}"
- Dont add any logging. Add appropriate comments.`,
responseHandler: {
func: "writeFile",
args: {
filePath: "user.dlFileName",
},
},
},
{
name: "Generate UpdateFunc for an input model struct",
template: `Task: Given a Go struct with properly defined database tags, generate the "Update" function code. This function should take an instance of input struct and update the database entry.\n
The input model struct is:\n
{selection}\n
Constraints:\n
- Use the sqlx for MySQL and Squirrel libraries for database handling and query building respectively. Dont generate the database connection code.
- Assume that string constants for the tablename and column names are available in a package called "spec". Dont use any hardcoded strings.
- Use "ctx context.Context" as the first argument to the function. Use appropriate context methods from the packages.
- Each function should appropriately handle any errors encountered during the database operation.
- Write the function as a method on a Datalayer struct as: "type DL struct { db *sqlx.DB}"
- Dont add any logging. Add appropriate comments.`,
responseHandler: {
func: "writeFile",
args: {
filePath: "user.dlFileName",
},
},
},
{
name: "Generate DeleteFunc for an input model struct",
template: `Task: Given a Go struct with properly defined database tags, generate the "Delete" function code. This function should take an id of input struct and delete the database entry.\n
The input model struct is:\n
{selection}\n
Constraints:\n
- Use the sqlx for MySQL and Squirrel libraries for database handling and query building respectively. Dont generate the database connection code.
- Assume that string constants for the tablename and column names are available in a package called "spec". Dont use any hardcoded strings.
- Use "ctx context.Context" as the first argument to the function. Use appropriate context methods from the packages.
- Each function should appropriately handle any errors encountered during the database operation.
- Write the function as a method on a Datalayer struct as: "type DL struct { db *sqlx.DB}"
- Dont add any logging. Add appropriate comments.`,
responseHandler: {
func: "writeFile",
args: {
filePath: "user.dlFileName",
},
},
},
{
name: "Generate CreateFunc: (no file write)",
template: `Task: Given a Go struct with properly defined database tags, generate the "Delete" function code. This function should take an id of input struct and delete the database entry.\n
The input model struct is:\n
{selection}\n
Constraints:\n
- Use the sqlx for MySQL and Squirrel libraries for database handling and query building respectively. Dont generate the database connection code.
- Assume that string constants for the tablename and column names are available in a package called "spec". Dont use any hardcoded strings.
- Use "ctx context.Context" as the first argument to the function. Use appropriate context methods from the packages.
- Each function should appropriately handle any errors encountered during the database operation.
- Write the function as a method on a Datalayer struct as: "type DL struct { db *sqlx.DB}"
- Dont add any logging. Add appropriate comments.`,
responseHandler: {
func: "getFileNameAndExtension",
args: {
filePath: "user.dlFileName",
},
},
},
],
functions: [
getFileNameAndExtension,
],
variables: [
{
name: "dlFileName",
value: ({ fileFolder, fileName, fileExtension }) =>
`${fileFolder}\\${fileName}_dl${fileExtension}`,
},
],
};