Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typesql-cli

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typesql-cli - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

1

code-generator.d.ts

@@ -13,2 +13,3 @@ import { SchemaDef, CamelCaseName, TsFieldDescriptor } from "./types";

export declare function generateFunction(camelCaseName: CamelCaseName, tsDescriptor: TsDescriptor, target: 'node' | 'deno'): string;
export declare function replaceOrderByParam(sql: string): string;
export declare function convertToCamelCaseName(name: string): CamelCaseName;

@@ -15,0 +16,0 @@ export declare function generateTsFile(client: DbClient, sqlFile: string, target: 'node' | 'deno'): Promise<void>;

7

code-generator.js

@@ -34,3 +34,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.generateTsFile = exports.convertToCamelCaseName = exports.generateFunction = exports.generateOrderByFunction = exports.generateOrderByType = exports.generateReturnType = exports.generateDataType = exports.generateParamsType = exports.generateReturnName = exports.escapeInvalidTsField = exports.renameInvalidNames = exports.generateTsDescriptor = void 0;
exports.generateTsFile = exports.convertToCamelCaseName = exports.replaceOrderByParam = exports.generateFunction = exports.generateOrderByFunction = exports.generateOrderByType = exports.generateReturnType = exports.generateDataType = exports.generateParamsType = exports.generateReturnName = exports.escapeInvalidTsField = exports.renameInvalidNames = exports.generateTsDescriptor = void 0;
const fs_1 = __importDefault(require("fs"));

@@ -277,6 +277,7 @@ const path_1 = __importStar(require("path"));

function replaceOrderByParam(sql) {
const patern = /(.*order\s+by\s*)(\?)(.*$)/i;
const newSql = sql.replace(patern, "$1${escapeOrderBy(params.orderBy)} $3");
const patern = /(.*order\s+by\s*)(\?)(.\n$)*/i;
const newSql = sql.replace(patern, "$1${escapeOrderBy(params.orderBy)}$3");
return newSql;
}
exports.replaceOrderByParam = replaceOrderByParam;
function writeTsFile(filePath, tsContent) {

@@ -283,0 +284,0 @@ fs_1.default.writeFileSync(filePath, tsContent);

@@ -361,4 +361,8 @@ "use strict";

};
const fromClause = querySpec.fromClause();
if (fromClause) {
walkFromClause(context, fromClause);
}
const whereClause = querySpec.whereClause();
//TODO - FROM, HAVING, BLAH
//TODO - HAVING, BLAH
if (whereClause) {

@@ -370,2 +374,14 @@ const whereExpr = whereClause === null || whereClause === void 0 ? void 0 : whereClause.expr();

}
function walkFromClause(context, fromClause) {
var _a;
const tableReferences = (_a = fromClause.tableReferenceList()) === null || _a === void 0 ? void 0 : _a.tableReference();
tableReferences === null || tableReferences === void 0 ? void 0 : tableReferences.forEach(tabeRef => {
tabeRef.joinedTable().forEach(joinedTable => {
const onExpr = joinedTable.expr();
if (onExpr) {
walkExpr(context, onExpr);
}
});
});
}
function walkExpr(context, expr) {

@@ -529,3 +545,3 @@ if (expr instanceof ts_mysql_parser_1.ExprIsContext) {

function walkSimpleExpr(context, simpleExpr) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprColumnRefContext) {

@@ -615,6 +631,18 @@ const fieldName = select_columns_1.splitName(simpleExpr.text);

}
if (runtimeFunctionCall.COALESCE_SYMBOL()) {
const exprList = (_c = runtimeFunctionCall.exprListWithParentheses()) === null || _c === void 0 ? void 0 : _c.exprList().expr();
if (exprList) {
const paramType = freshVar('?', '?');
const params = {
kind: 'VariableLengthParams',
paramType: paramType
};
walkExprListParameters(context, exprList, params);
return paramType;
}
}
throw Error('Function not supported: ' + runtimeFunctionCall.text);
}
if (simpleExpr instanceof ts_mysql_parser_1.SimpleExprFunctionContext) {
const functionIdentifier = ((_c = simpleExpr.functionCall().pureIdentifier()) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()) || ((_d = simpleExpr.functionCall().qualifiedIdentifier()) === null || _d === void 0 ? void 0 : _d.text.toLowerCase());
const functionIdentifier = ((_d = simpleExpr.functionCall().pureIdentifier()) === null || _d === void 0 ? void 0 : _d.text.toLowerCase()) || ((_e = simpleExpr.functionCall().qualifiedIdentifier()) === null || _e === void 0 ? void 0 : _e.text.toLowerCase());
if (functionIdentifier === 'concat_ws' || (functionIdentifier === null || functionIdentifier === void 0 ? void 0 : functionIdentifier.toLowerCase()) === 'concat') {

@@ -730,3 +758,3 @@ const varcharType = freshVar(simpleExpr.text, 'varchar');

const functionType = freshVar(simpleExpr.text, '?');
const inSumExpr = (_e = simpleExpr.sumExpr().inSumExpr()) === null || _e === void 0 ? void 0 : _e.expr();
const inSumExpr = (_f = simpleExpr.sumExpr().inSumExpr()) === null || _f === void 0 ? void 0 : _f.expr();
if (inSumExpr) {

@@ -745,3 +773,3 @@ const inSumExprType = walkExpr(context, inSumExpr);

const functionType = freshVar(simpleExpr.text, 'bigint');
const inSumExpr = (_f = simpleExpr.sumExpr().inSumExpr()) === null || _f === void 0 ? void 0 : _f.expr();
const inSumExpr = (_g = simpleExpr.sumExpr().inSumExpr()) === null || _g === void 0 ? void 0 : _g.expr();
if (inSumExpr) {

@@ -754,3 +782,3 @@ walkExpr(context, inSumExpr);

const functionType = freshVar(simpleExpr.text, '?');
const inSumExpr = (_g = simpleExpr.sumExpr().inSumExpr()) === null || _g === void 0 ? void 0 : _g.expr();
const inSumExpr = (_h = simpleExpr.sumExpr().inSumExpr()) === null || _h === void 0 ? void 0 : _h.expr();
if (inSumExpr) {

@@ -772,3 +800,3 @@ const inSumExprType = walkExpr(context, inSumExpr);

if (literal.textLiteral()) {
const text = (_h = literal.textLiteral()) === null || _h === void 0 ? void 0 : _h.text.slice(1, -1); //remove quotes
const text = (_j = literal.textLiteral()) === null || _j === void 0 ? void 0 : _j.text.slice(1, -1); //remove quotes
return freshVar('varchar', 'varchar');

@@ -837,7 +865,7 @@ }

});
const elseExpr = (_j = simpleExpr.elseExpression()) === null || _j === void 0 ? void 0 : _j.expr();
const elseExpr = (_k = simpleExpr.elseExpression()) === null || _k === void 0 ? void 0 : _k.expr();
if (elseExpr) {
const elseType = walkExpr(context, elseExpr);
context.constraints.push({
expression: (_k = simpleExpr.elseExpression()) === null || _k === void 0 ? void 0 : _k.text,
expression: (_l = simpleExpr.elseExpression()) === null || _l === void 0 ? void 0 : _l.text,
type1: caseType,

@@ -844,0 +872,0 @@ type2: elseType.kind == 'TypeOperator' ? elseType.types[0] : elseType,

@@ -160,3 +160,3 @@ "use strict";

function inferNotNullRuntimeFunctionCall(simpleExprRuntimeFunction, dbSchema, fromColumns) {
var _a;
var _a, _b;
const functionCall = simpleExprRuntimeFunction.runtimeFunctionCall();

@@ -181,2 +181,6 @@ if (functionCall.NOW_SYMBOL() || functionCall.CURDATE_SYMBOL() || functionCall.CURTIME_SYMBOL()) {

}
if (functionCall.COALESCE_SYMBOL()) {
const exprList = (_b = functionCall.exprListWithParentheses()) === null || _b === void 0 ? void 0 : _b.exprList().expr();
return exprList.every(expr => inferNotNullExpr(expr, dbSchema, fromColumns));
}
throw Error('Function not supported: ' + functionCall.text);

@@ -183,0 +187,0 @@ }

@@ -99,3 +99,3 @@ "use strict";

//if( sum && (type1 == 'decimal' && type2 == 'number') || type1 == 'number' && type2 == 'decimal' ) return 'double';
const order = ['number', 'tinyint', 'int', 'bigint', 'decimal', 'float', 'double'];
const order = ['number', 'tinyint', 'smallint', 'int', 'bigint', 'decimal', 'float', 'double'];
const indexType1 = order.indexOf(type1);

@@ -102,0 +102,0 @@ const indexType2 = order.indexOf(type2);

{
"name": "typesql-cli",
"version": "0.1.6",
"version": "0.1.7",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc