Recently, I've encountered a tricky problem: at work, the type of database used varies from project to project. I used to write SQL statements in Oracle, but every time I finished, I encountered errors, and finally realized that the project's database is not Oracle. to avoid this situation, I need to spend extra time to find out the SQL syntax of different database versions, which seriously delayed my work efficiency.
In order to increase my productivity, I decided to write my own script to be able to quickly access the required database syntax, thus saving time and focusing on other more important tasks.
Today I used the utools platform to focus on automated scripting. The build of this platform is complete and all the environments and dependencies are configured properly. Now, the remaining task is to write the scripts myself to bring my needs and functionality to fruition.
preliminary
First, you need to download utools. This tool is known for its convenience and efficiency, allowing you to quickly call out the required functions when needed, truly realize the "come when called, ready to go".
This tool should be an essential tool for many programmers in their daily work. Not only does it offer a wealth of features, but also extensive community support. Next, you need to head to the store and download two very useful plugins for free - Automation Script and JSON Editor.
In this tool, you can find many ready-made automation scripts, ready to download and use. However, these scripts didn't exactly fit my needs, so I decided to implement one myself.
Due to the syntactical differences between different versions of the database, I chose to present my implementation in JSON format for easy viewing and understanding. In this process, I also downloaded the JSON editor since it involves visual presentation of the data. In this way, you can operate and analyze the data more intuitively, rather than just looking at a simple string, which greatly improves the convenience and effectiveness of the operation.
Writing scripts
Next, we can create this script on our own, as follows.
I will write out the basic code for reference and learning.
var conver = parseToJson()
var res = (conver, null, 4);
('"'+conver+'"'+'Completed')
('Json', res);
function parseToJson(data) {
const json = {"type":"text","word":"word"};
return json;
}
The main purpose of this code is to pass JSON data to the JSON editor plugin for visual display and easier operation. As shown in the figure:
Since this code is developed based on utools platform, some of the writings in it use the APIs integrated by utools. in order to facilitate a better understanding of these writings and the implementation logic behind them, it is recommended that you refer to the utools development documentation, where detailed descriptions and examples are provided. I won't go into the details of each API individually here.
Versions of writing
The rest is left for you to explore and experiment with various writing styles on your own. Depending on your own needs, you may have the flexibility to add or modify code to achieve specific features or optimizations.
To help you get started faster, I'm sharing some of my go-to write-ups here for your reference.
// Get current time
const now = new Date();
const formattedDate = ().slice(0, 19).replace('T', ' '); // formatted as 'YYYY-MM-DD HH:mm:ss'
const json = {
"appointed time": {
"Oracle": `to_date('${formattedDate}', 'yyyy-mm-dd hh24:mi:ss')`,
"MySQL": `STR_TO_DATE('${formattedDate}', '%Y-%m-%d %H:%i:%s')`,
"PostgreSQL": `TO_TIMESTAMP('${formattedDate}', 'YYYY-MM-DD HH24:MI:SS')`,
"SQL Server": `CONVERT(DATETIME, '${formattedDate}', 120)`,
"SQLite": `DATETIME('${formattedDate}')`
},
"current time": {
"Oracle": "SYSDATE",
"MySQL": "NOW()",
"PostgreSQL": "CURRENT_TIMESTAMP",
"SQL Server": "GETDATE()",
"SQLite": "CURRENT_TIMESTAMP"
},
"time-to-string": {
"Oracle": "TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')",
"MySQL": "DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s')",
"PostgreSQL": "TO_CHAR(CURRENT_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS')",
"SQL Server": "CONVERT(VARCHAR, GETDATE(), 120)",
"SQLite": "STRFTIME('%Y-%m-%d %H:%M:%S', 'now')"
}
};
Realization effects
The next step is to automatically initiate the JSON call, after which you just need to copy the generated result for use. Despite the small size of this tool, it was able to help me save a lot of time and effort.
Once you have your script on the shelf, you can easily invoke it by simply entering the appropriate configuration keywords in utools.
Run successfully, the system has successfully completed the operation, the specific results are shown in the figure.
I hope that this tool will be helpful for everyone to improve their productivity.
summarize
If you guys have any gadgets you want to implement, utools is definitely a platform worth considering. Not only is it powerful, but it's especially suited to the way programmers work and meets our needs for flexibility and customizability.