refactor: remove typescript and refactor

This commit is contained in:
dunak-debug committed 2021-08-17 02:58:31 +02:00
1 parent d2a9a433bb
commit 8df05c748b
11 files changed
+283 -219

No files matched your search

+107 -30
View File
@@ -1,41 +1,118 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp
pids
# Logs
logs
results
tmp
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Build
public/css/main.css
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Coverage reports
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# API keys and secrets
.env
# nyc test coverage
.nyc_output
# Dependency directory
node_modules
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# Editors
.idea
*.iml
# node-waf configuration
.lock-wscript
# OS metadata
.DS_Store
Thumbs.db
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Ignore built ts files
dist/**/*
# Dependency directories
node_modules/
jspm_packages/
# ignore yarn.lock
yarn.lock
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
.env.production
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
-45
View File
@@ -1,45 +0,0 @@
# test directories
__tests__
test
tests
powered-test
# asset directories
docs
doc
website
images
assets
# examples
example
examples
# code coverage directories
coverage
.nyc_output
# build scripts
Makefile
Gulpfile.js
Gruntfile.js
# configs
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml
# misc
*.md
+1 -1
View File
@@ -7,4 +7,4 @@ version '1.0.0'
url 'https://github.com/overextended/oxmysql'
author 'Dunak'
server_scripts {'dist/oxmysql.js', 'wrapper.lua'}
server_scripts {'oxmysql.js', 'wrapper.lua'}
+52
View File
@@ -0,0 +1,52 @@
/// <reference path="node_modules\@citizenfx\server\index.d.ts" />
const { createPool } = require('mysql2/promise');
const pool = createPool({
host: 'localhost',
user: 'root',
database: 'es_extended'
});
const execute = async (query, parameters) => {
try {
console.time(query);
const [result] = await pool.execute(query, parameters);
console.timeEnd(query);
return result;
} catch (error) {
console.error(error.message);
return;
}
}
exports("execute", (query, parameters = [], callback = () => { }) => {
execute(query, parameters)
.then(result => callback(result && result.affectedRows));
process._tickCallback()
});
exports("fetch", (query, parameters = [], callback = () => { }) => {
execute(query, parameters)
.then(result => callback(result));
process._tickCallback();
});
exports("single", (query, parameters = [], callback = () => { }) => {
execute(query, parameters)
.then(result => callback(result && result[0] && result[0][0]));
process._tickCallback();
});
exports("scalar", (query, parameters = [], callback = () => { }) => {
execute(query, parameters)
.then(result => callback(result && result[0] && result[0][0] && Object.values(result[0][0])[0]));
process._tickCallback();
});
exports("insert", (query, parameters = [], callback = () => { }) => {
execute(query, parameters)
.then(result => callback(result && result.insertId));
process._tickCallback();
});
+1 -14
View File
@@ -2,26 +2,13 @@
"name": "oxmysql",
"private": "true",
"version": "1.0.0",
"main": "src/index.ts",
"main": "oxmysql.js",
"description": "FiveM MySQL wrapper using faster mysql2",
"repository": "[email protected]:overextended/oxmysql.git",
"author": "dunak-debug <[email protected]>",
"license": "GPL-3.0-or-later",
"scripts": {
"start": "webpack --watch --progress",
"build": "webpack"
},
"dependencies": {
"@citizenfx/server": "^2.0.4376-1",
"mysql2": "^2.3.0"
},
"devDependencies": {
"@types/node": "^16.6.1",
"cardinal": "^2.1.1",
"ts-loader": "^9.2.5",
"ts-node": "^10.2.0",
"typescript": "^4.3.5",
"webpack": "^5.50.0",
"webpack-cli": "^4.7.2"
}
}
-82
View File
@@ -1,82 +0,0 @@
import { OkPacket, RowDataPacket } from "mysql2/promise";
import { pool } from "./pool";
global.exports(
"execute",
(
query: string,
parameters: { [key: string]: any },
callback: (result: any) => void
) => {
pool
.execute(query, parameters)
.then((result) => {
callback(result[0]);
})
.catch((error) => {
callback(false);
console.log(error);
});
(<any>process)._tickCallback();
}
);
global.exports(
"single",
(
query: string,
parameters: { [key: string]: any },
callback: (result: RowDataPacket[] | false) => void
) => {
pool
.execute(query, parameters)
.then((result) => {
callback(result[0][0]);
})
.catch((error) => {
callback(false);
console.log(error);
});
(<any>process)._tickCallback();
}
);
global.exports(
"scalar",
(
query: string,
parameters: { [key: string]: any },
callback: (result: unknown) => void
) => {
pool
.execute(query, parameters)
.then((result) => {
callback(Object.values(result[0][0])[0]);
})
.catch((error) => {
callback(false);
console.log(error);
});
(<any>process)._tickCallback();
}
);
global.exports(
"insert",
(
query: string,
parameters: { [key: string]: any },
callback: (result: OkPacket | false) => void
) => {
pool
.execute(query, parameters)
.then((result) => {
callback(<OkPacket>result[0]);
})
.catch((error) => {
callback(false);
console.log(error);
});
(<any>process)._tickCallback();
}
);
-9
View File
@@ -1,9 +0,0 @@
import { createPool } from "mysql2/promise";
const pool = createPool({
host: "localhost",
user: "root",
database: "es_extended",
});
export { pool };
-9
View File
@@ -1,9 +0,0 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"types": ["@citizenfx/server", "@types/node"]
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
-27
View File
@@ -1,27 +0,0 @@
const path = require('path');
module.exports = {
mode: "production",
optimization: {
minimize: false
},
target: 'node',
entry: './src/index.ts',
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
include: path.resolve(__dirname, 'src'),
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
output: {
filename: 'oxmysql.js',
path: path.resolve(__dirname, 'dist'),
},
};
+19 -2
View File
@@ -1,5 +1,5 @@
---
-- Execute query and fetch all result
-- Execute query and fetch affected rows
--
-- @param query tring
-- @param parameters table
@@ -15,6 +15,23 @@ local function executeSync(query, parameters)
end
exports('executeSync', executeSync)
---
-- Execute query and fetch all result
--
-- @param query tring
-- @param parameters table
--
-- @return table with result
--
local function fetchSync(query, parameters)
local p = promise.new()
exports['oxmysql']:fetch(query, parameters, function(result)
p:resolve(result)
end)
return Citizen.Await(p)
end
exports('fetchSync', fetchSync)
---
-- Execute query and fetch first row
--
@@ -50,7 +67,7 @@ end
exports('scalarSync', scalarSync)
---
-- Insert data and return table with inserted data
-- Insert data and return inserted id
--
-- @param query tring
-- @param parameters table
+103
View File
@@ -0,0 +1,103 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
"@citizenfx/server@^2.0.4376-1":
version "2.0.4376-1"
resolved "https://registry.yarnpkg.com/@citizenfx/server/-/server-2.0.4376-1.tgz#6cc9e034bc463a031df40532f278b9f309b7f258"
integrity sha512-xIqpuSwbyga3ysSJ3NfiDeJ6+L3cEHI+vRF45IjMP3U0E4bMZLGrjoSXBbndDJjd97uPdak3HPZD4/AC0HBnIw==
denque@^1.4.1:
version "1.5.0"
resolved "https://registry.yarnpkg.com/denque/-/denque-1.5.0.tgz#773de0686ff2d8ec2ff92914316a47b73b1c73de"
integrity sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==
generate-function@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.3.1.tgz#f069617690c10c868e73b8465746764f97c3479f"
integrity sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==
dependencies:
is-property "^1.0.2"
iconv-lite@^0.6.2:
version "0.6.3"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.6.3.tgz#a52f80bf38da1952eb5c681790719871a1a72501"
integrity sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==
dependencies:
safer-buffer ">= 2.1.2 < 3.0.0"
is-property@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84"
integrity sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=
long@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==
lru-cache@^4.1.3:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"
lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
dependencies:
yallist "^4.0.0"
mysql2@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/mysql2/-/mysql2-2.3.0.tgz#600f5cc27e397dfb77b59eac93666434f88e8079"
integrity sha512-0t5Ivps5Tdy5YHk5NdKwQhe/4Qyn2pload+S+UooDBvsqngtzujG1BaTWBihQLfeKO3t3122/GtusBtmHEHqww==
dependencies:
denque "^1.4.1"
generate-function "^2.3.1"
iconv-lite "^0.6.2"
long "^4.0.0"
lru-cache "^6.0.0"
named-placeholders "^1.1.2"
seq-queue "^0.0.5"
sqlstring "^2.3.2"
named-placeholders@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/named-placeholders/-/named-placeholders-1.1.2.tgz#ceb1fbff50b6b33492b5cf214ccf5e39cef3d0e8"
integrity sha512-wiFWqxoLL3PGVReSZpjLVxyJ1bRqe+KKJVbr4hGs1KWfTZTQyezHFBbuKj9hsizHyGV2ne7EMjHdxEGAybD5SA==
dependencies:
lru-cache "^4.1.3"
pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM=
"safer-buffer@>= 2.1.2 < 3.0.0":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
seq-queue@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/seq-queue/-/seq-queue-0.0.5.tgz#d56812e1c017a6e4e7c3e3a37a1da6d78dd3c93e"
integrity sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4=
sqlstring@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/sqlstring/-/sqlstring-2.3.2.tgz#cdae7169389a1375b18e885f2e60b3e460809514"
integrity sha512-vF4ZbYdKS8OnoJAWBmMxCQDkiEBkGQYU7UZPtL8flbDRSNkhaXvRJ279ZtI6M+zDaQovVU4tuRgzK5fVhvFAhg==
yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=
yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==