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.9 to 0.2.0

sqls/orderByEscaped.d.ts

5

code-generator.js

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

function generateOrderByType(queryName, orderByColumns) {
const orderByColumnsType = orderByColumns === null || orderByColumns === void 0 ? void 0 : orderByColumns.map(col => `'${col}'`).join(' | ');
const orderByColumnsType = orderByColumns === null || orderByColumns === void 0 ? void 0 : orderByColumns.map(col => `"${col}"`).join(' | ');
const orderByTypeName = generateOrderByTypeName(queryName);

@@ -200,4 +200,5 @@ const orderByType = orderByColumns ? `

functionParams += ', data: ' + generateDataTypeName(camelCaseName);
if (tsDescriptor.parameters.length > 0)
if (tsDescriptor.parameters.length > 0 || (tsDescriptor.orderByColumns && tsDescriptor.orderByColumns.length > 0)) {
functionParams += ', params: ' + generateParamsTypeName(camelCaseName);
}
const allParameters = [];

@@ -204,0 +205,0 @@ if (tsDescriptor.data)

2

describe-query.js

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

function verifyNotInferred(type) {
if (type == '?')
if (type == '?' || type == 'any')
return "varchar";

@@ -121,0 +121,0 @@ if (type == 'number')

@@ -8,4 +8,4 @@ export declare enum FlagEnum {

}
export declare type InferType = MySqlType | '?' | 'number';
export declare type MySqlType = 'decimal' | 'decimal[]' | 'tinyint' | 'tinyint[]' | 'smallint' | 'smallint[]' | 'int' | 'int[]' | 'float' | 'float[]' | 'double' | 'double[]' | 'null' | 'timestamp' | 'bigint' | 'bigint[]' | 'mediumint' | 'mediumint[]' | 'date' | 'time' | 'datetime' | 'year' | 'year[]' | 'newdate' | 'varchar' | 'bit' | 'timestamp2' | 'datetime2' | 'time2' | 'json' | 'enum' | 'set' | 'tinytext' | 'mediumtext' | 'longtext' | 'text' | 'varbinary' | 'binary' | 'geometry';
export declare type InferType = MySqlType | '?' | 'number' | 'any';
export declare type MySqlType = 'decimal' | 'decimal[]' | 'tinyint' | 'tinyint[]' | 'smallint' | 'smallint[]' | 'int' | 'int[]' | 'float' | 'float[]' | 'double' | 'double[]' | 'null' | 'timestamp' | 'bigint' | 'bigint[]' | 'mediumint' | 'mediumint[]' | 'date' | 'time' | 'datetime' | 'year' | 'year[]' | 'newdate' | 'varchar' | 'bit' | 'timestamp2' | 'datetime2' | 'time2' | 'json' | 'enum' | 'set' | 'tinytext' | 'mediumtext' | 'longtext' | 'text' | 'varbinary' | 'binary' | 'char' | 'char[]' | 'geometry';
export declare type TsType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean' | 'boolean[]' | 'Date' | 'Date[]' | 'Object' | 'Object[]' | 'Buffer' | 'any' | 'null';

@@ -12,0 +12,0 @@ export declare function converToTsType(mySqlType: MySqlType): TsType;

@@ -59,3 +59,6 @@ "use strict";

case 'binary':
return 'Buffer';
case 'char':
return 'string';
case 'char[]':
return 'string[]';
case 'enum':

@@ -62,0 +65,0 @@ case 'set':

@@ -24,6 +24,4 @@ import { RuleContext } from "antlr4ts";

mostGeneralType?: true;
coercionType?: 'Sum' | 'Irrestrict' | 'SumFunction';
list?: true;
sum?: 'sum';
strict?: boolean;
functionName?: 'sum';
};

@@ -30,0 +28,0 @@ export declare type InferenceContext = {

@@ -423,4 +423,3 @@ "use strict";

type1: typeLeft,
type2: typeRight,
strict: true
type2: typeRight
});

@@ -437,4 +436,3 @@ return freshVar(boolPri.text, 'tinyint');

type1: typeLeft,
type2: typeRight,
strict: true
type2: typeRight
});

@@ -455,4 +453,3 @@ return freshVar(boolPri.text, 'tinyint');

type2: rightType,
mostGeneralType: true,
strict: true
mostGeneralType: true
});

@@ -521,3 +518,3 @@ return rightType;

mostGeneralType: true,
sum: 'sum'
coercionType: 'Sum'
});

@@ -529,3 +526,3 @@ context.constraints.push({

mostGeneralType: true,
sum: 'sum'
coercionType: 'Sum'
});

@@ -537,3 +534,3 @@ context.constraints.push({

mostGeneralType: true,
sum: 'sum'
coercionType: 'Sum'
});

@@ -640,5 +637,14 @@ return bitExprType;

kind: 'VariableLengthParams',
paramType: paramType
paramType: 'any'
};
walkExprListParameters(context, exprList, params);
const paramsTypeList = walkExprListParameters(context, exprList, params);
paramsTypeList.forEach((typeVar, paramIndex) => {
context.constraints.push({
expression: runtimeFunctionCall.text + '_param' + (paramIndex + 1),
type1: paramType,
type2: typeVar,
mostGeneralType: true,
coercionType: 'Irrestrict'
});
});
return paramType;

@@ -655,3 +661,3 @@ }

kind: 'VariableLengthParams',
paramType: varcharType
paramType: '?'
};

@@ -792,3 +798,3 @@ walkFunctionParameters(context, simpleExpr, params);

mostGeneralType: true,
functionName: 'sum'
coercionType: 'SumFunction'
});

@@ -892,9 +898,10 @@ }

const exprType = walkExpr(context, expr);
const paramType = params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : freshVar(params.paramType, params.paramType);
context.constraints.push({
expression: expr.text,
type1: exprType,
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : params.paramType,
type2: paramType,
mostGeneralType: true
});
return exprType;
return paramType;
});

@@ -912,3 +919,3 @@ }

type1: exprType,
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : params.paramType,
type2: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : freshVar(params.paramType, params.paramType),
mostGeneralType: true

@@ -926,3 +933,3 @@ });

expression: inExpr.text,
type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : params.paramType,
type1: params.kind == 'FixedLengthParams' ? params.paramsType[paramIndex] : freshVar(params.paramType, params.paramType),
type2: inSumExprType,

@@ -929,0 +936,0 @@ mostGeneralType: true

@@ -43,2 +43,6 @@ "use strict";

const typeInferenceResult = collect_constraints_1.analiseTree(queryContext, dbSchema);
// const newTypeInference : TypeInferenceResult = {
// columns: typeInferenceResult.columns.map( col => verifyNotInferred(col)),
// parameters: typeInferenceResult.parameters.map(paramType => verifyNotInferred(paramType))
// }
return typeInferenceResult;

@@ -45,0 +49,0 @@ }

@@ -18,4 +18,3 @@ "use strict";

type1: ty1.types[i],
type2: ty2.types[i],
strict: true
type2: ty2.types[i]
};

@@ -30,3 +29,3 @@ unifyOne(newConstr, substitutions);

if (ty2.type != '?') {
const bestType = getBestPossibleType(ty1.type, ty2.type, constraint.mostGeneralType, constraint.sum);
const bestType = getBestPossibleType(ty1.type, ty2.type, constraint.mostGeneralType, constraint.coercionType);
ty1.type = bestType;

@@ -39,3 +38,3 @@ ty2.type = bestType;

const numberTypes = ['number', 'tinyint', 'int', 'bigint', 'decimal', 'double'];
if (constraint.sum && constraint.mostGeneralType && numberTypes.indexOf(ty1.type) >= 0) {
if (constraint.coercionType == 'Sum' && numberTypes.indexOf(ty1.type) >= 0) {
//In the expression ty1 + ?, ty2 = double

@@ -54,10 +53,11 @@ ty1.type = 'double';

// }
const exactValueNumbers = ['int', 'bigint', 'decimal'];
if (constraint.functionName && (exactValueNumbers.indexOf(ty2.type) >= 0)) {
ty2.type = 'decimal';
if (constraint.coercionType == 'SumFunction') {
const exactValueNumbers = ['int', 'bigint', 'decimal'];
if (exactValueNumbers.indexOf(ty2.type) >= 0) {
ty2.type = 'decimal';
}
else {
ty2.type = 'double';
}
}
const aproximatedValues = ['float', 'double'];
if (constraint.functionName && (aproximatedValues.indexOf(ty2.type) >= 0)) {
ty2.type = 'double';
}
substitutions[ty1.id] = ty2;

@@ -90,13 +90,19 @@ ty1.type = ty2.type;

}
function getBestPossibleType(type1, type2, max, sum) {
if (!sum && type1 === type2)
function getBestPossibleType(type1, type2, max, coercionType) {
if (type1 == 'any') {
return coercionType == 'Irrestrict' ? 'any' : type2;
}
if (type2 == 'any') {
return coercionType == 'Irrestrict' ? 'any' : type1;
}
if (coercionType != 'Sum' && type1 === type2)
return type1;
if (sum && max && type1 == 'number' && type2 == 'int' || type1 == 'int' && type2 == 'number')
if (coercionType == 'Sum' && max && type1 == 'number' && type2 == 'int' || type1 == 'int' && type2 == 'number')
return 'double';
// if( sum && type1 == 'number' && type2 == 'bigint' || type1 == 'bigint' && type2 == 'number') return 'double';
if (sum && max && type1 == 'int' && type2 == 'int')
// if( coercionType == 'Sum' && type1 == 'number' && type2 == 'bigint' || type1 == 'bigint' && type2 == 'number') return 'double';
if (coercionType == 'Sum' && max && type1 == 'int' && type2 == 'int')
return 'bigint';
if (sum && max && ((type1 == 'int' && type2 == 'double') || type1 == 'double' && type2 == 'int'))
if (coercionType == 'Sum' && max && ((type1 == 'int' && type2 == 'double') || type1 == 'double' && type2 == 'int'))
return 'double';
if (sum && max && ((type1 == 'bigint' && type2 == 'double') || type1 == 'double' && type2 == 'bigint'))
if (coercionType == 'Sum' && max && ((type1 == 'bigint' && type2 == 'double') || type1 == 'double' && type2 == 'bigint'))
return 'double';

@@ -103,0 +109,0 @@ //if( sum && (type1 == 'decimal' && type2 == 'number') || type1 == 'number' && type2 == 'decimal' ) return 'double';

{
"name": "typesql-cli",
"version": "0.1.9",
"version": "0.2.0",
"description": "",

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

@@ -59,2 +59,4 @@ Obs.: This is a WIP experimental project.

# Examples
[Order by and limit clauses](/docs/orderBy_limit.md)

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

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