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.5.1 to 0.5.2

2

mysql-query-analyzer/collect-constraints.d.ts

@@ -47,3 +47,3 @@ import { RuleContext } from "antlr4ts";

export declare function unionTypeResult(type1: InferType, type2: InferType): any;
export declare function analiseQuerySpecification(querySpec: QuerySpecificationContext, dbSchema: ColumnSchema[], withSchema: ColumnSchema[], namedParameters: string[], fromColumns: ColumnDef[]): TypeInferenceResult;
export declare function analiseQuerySpecification(querySpec: QuerySpecificationContext, dbSchema: ColumnSchema[], withSchema: ColumnSchema[], fromColumns: ColumnDef[], namedParameters: string[]): TypeInferenceResult;
export declare function generateTypeInfo(namedNodes: TypeVar[], constraints: Constraint[]): InferType[];

@@ -50,0 +50,0 @@ export declare function walkQuerySpecification(context: InferenceContext, querySpec: QuerySpecificationContext): TypeOperator;

@@ -12,2 +12,9 @@ "use strict";

const queryTree = (0, parse_1.parse)(sql);
const context = {
dbSchema,
withSchema,
parameters: [],
constraints: [],
fromColumns: []
};
const selectStatement = (_a = queryTree.simpleStatement()) === null || _a === void 0 ? void 0 : _a.selectStatement();

@@ -14,0 +21,0 @@ if (selectStatement) {

@@ -12,5 +12,5 @@ import { QueryContext, QuerySpecificationContext, SubqueryContext, QueryExpressionParensContext } from 'ts-mysql-parser';

export declare function extractQueryInfoFromQuerySpecification(querySpec: QuerySpecificationContext, dbSchema: ColumnSchema[], withSchema: ColumnSchema[], namedParameters: string[]): TypeAndNullInferResult;
export declare function extractQueryInfo(sql: string, dbSchema: ColumnSchema[], withSchema?: ColumnSchema[]): QueryInfoResult | InsertInfoResult | UpdateInfoResult | DeleteInfoResult;
export declare function extractQueryInfo(sql: string, dbSchema: ColumnSchema[]): QueryInfoResult | InsertInfoResult | UpdateInfoResult | DeleteInfoResult;
export declare function analiseQuery(querySpec: QuerySpecificationContext[], dbSchema: ColumnSchema[], withSchema: ColumnSchema[], namedParameters: string[]): TypeAndNullInferResult;
export declare function getQuerySpecificationsFromSelectStatement(selectStatement: any | QueryExpressionParensContext | SubqueryContext): QuerySpecificationContext[];
//# sourceMappingURL=parse.d.ts.map

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

const fromColumns = (0, select_columns_1.getColumnsFrom)(querySpec, dbSchema, withSchema);
const inferResult = (0, collect_constraints_1.analiseQuerySpecification)(querySpec, dbSchema, withSchema, namedParameters, fromColumns);
const inferResult = (0, collect_constraints_1.analiseQuerySpecification)(querySpec, dbSchema, withSchema, fromColumns, namedParameters);
// console.log("inferResult=", inferResult);

@@ -138,6 +138,13 @@ const columnNullability = (0, infer_column_nullability_1.inferNotNull)(querySpec, dbSchema, withSchema);

//TODO - withSchema: ColumnSchema[] DEFAULT VALUE
function extractQueryInfo(sql, dbSchema, withSchema = []) {
function extractQueryInfo(sql, dbSchema) {
var _a, _b, _c, _d;
const { sql: processedSql, namedParameters } = (0, describe_query_1.preprocessSql)(sql);
const tree = parse(processedSql);
const context = {
dbSchema,
withSchema: [],
parameters: [],
constraints: [],
fromColumns: []
};
if (tree instanceof ts_mysql_parser_1.QueryContext) {

@@ -156,3 +163,3 @@ const selectStatement = (_a = tree.simpleStatement()) === null || _a === void 0 ? void 0 : _a.selectStatement();

if (withClause) {
const withClauseResults = analyseWithClause(withClause, dbSchema);
const withClauseResults = analyseWithClause(withClause, dbSchema, []);
withClauseResults.forEach(withClauseResult => {

@@ -171,6 +178,7 @@ const withSchema = withClauseResult.queryResult.columns.map(colDef => ({

}
context.withSchema = allWithSchema;
const queryExpressionBody = queryExpression.queryExpressionBody() || queryExpression.queryExpressionParens();
if (queryExpressionBody) {
const querySpec = getQuerySpecificationsFromSelectStatement(queryExpressionBody);
const mainQueryResult = analiseQuery(querySpec, dbSchema, allWithSchema, namedParameters);
const mainQueryResult = analiseQuery(querySpec, context.dbSchema, context.withSchema, namedParameters);
const orderByParameters = extractOrderByParameters(selectStatement);

@@ -182,3 +190,3 @@ const limitParameters = extractLimitParameters(selectStatement);

.concat(limitParameters);
const fromColumns = (0, select_columns_1.getColumnsFrom)(querySpec[0], dbSchema, allWithSchema);
const fromColumns = (0, select_columns_1.getColumnsFrom)(querySpec[0], context.dbSchema, context.withSchema);
const multipleRowsResult = isMultipleRowResult(selectStatement, fromColumns);

@@ -201,4 +209,4 @@ const resultWithoutOrderBy = {

if (insertStatement) {
const insertColumns = (0, collect_constraints_1.getInsertColumns)(insertStatement, dbSchema);
const typeInfer = (0, collect_constraints_1.analiseInsertStatement)(insertStatement, insertColumns, withSchema);
const insertColumns = (0, collect_constraints_1.getInsertColumns)(insertStatement, context.dbSchema);
const typeInfer = (0, collect_constraints_1.analiseInsertStatement)(insertStatement, insertColumns, context.withSchema);
return typeInfer;

@@ -208,3 +216,3 @@ }

if (updateStatement) {
const typeInfer = (0, collect_constraints_1.analiseUpdateStatement)(updateStatement, dbSchema, withSchema);
const typeInfer = (0, collect_constraints_1.analiseUpdateStatement)(updateStatement, context.dbSchema, context.withSchema);
return typeInfer;

@@ -214,3 +222,3 @@ }

if (deleteStatement) {
const typeInfer = (0, collect_constraints_1.analiseDeleteStatement)(deleteStatement, dbSchema, withSchema);
const typeInfer = (0, collect_constraints_1.analiseDeleteStatement)(deleteStatement, context.dbSchema, context.withSchema);
return typeInfer;

@@ -260,7 +268,7 @@ }

}
function analyseWithClause(withClause, dbSchema) {
function analyseWithClause(withClause, dbSchema, withSchema) {
return withClause.commonTableExpression().map(commonTableExpression => {
const identifier = commonTableExpression.identifier().text;
const subQuery = commonTableExpression.subquery();
const queryResult = (0, select_columns_1.analyzeSubQuery)(subQuery, dbSchema);
const queryResult = (0, select_columns_1.analyzeSubQuery)(subQuery, dbSchema, withSchema);
return {

@@ -267,0 +275,0 @@ identifier,

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

export declare function getColumnNames(querySpec: QuerySpecificationContext, fromColumns: ColumnDef[]): string[];
export declare function getColumnsFrom(ctx: QuerySpecificationContext, dbSchema: ColumnSchema[], withSchema?: ColumnSchema[]): ColumnDef[];
export declare function analyzeSubQuery(subQuery: SubqueryContext, dbSchema: ColumnSchema[]): import("./types").TypeAndNullInferResult;
export declare function getColumnsFrom(ctx: QuerySpecificationContext, dbSchema: ColumnSchema[], withSchema: ColumnSchema[]): ColumnDef[];
export declare function analyzeSubQuery(subQuery: SubqueryContext, dbSchema: ColumnSchema[], withSchema: ColumnSchema[]): import("./types").TypeAndNullInferResult;
export declare function splitName(fieldName: string): FieldName;

@@ -12,0 +12,0 @@ export declare function findColumn(fieldName: FieldName, columns: ColumnDef[]): ColumnDef;

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

// TODO - withSchema: ColumnSchema[] DEFAULT VALUE []
function getColumnsFrom(ctx, dbSchema, withSchema = []) {
function getColumnsFrom(ctx, dbSchema, withSchema) {
var _a, _b;

@@ -193,3 +193,3 @@ const tableReferences = (_b = (_a = ctx.fromClause()) === null || _a === void 0 ? void 0 : _a.tableReferenceList()) === null || _b === void 0 ? void 0 : _b.tableReference();

const tableAlias = (_a = derivadTable.tableAlias()) === null || _a === void 0 ? void 0 : _a.text;
return extractFieldsFromSubquery(subQuery, dbSchema, tableAlias);
return extractFieldsFromSubquery(subQuery, dbSchema, withSchema, tableAlias);
}

@@ -204,12 +204,12 @@ }

}
function analyzeSubQuery(subQuery, dbSchema) {
function analyzeSubQuery(subQuery, dbSchema, withSchema) {
const queries = (0, parse_1.getQuerySpecificationsFromSelectStatement)(subQuery);
const queryResult = (0, parse_1.analiseQuery)(queries, dbSchema, [], []); //TODO - WHY []?
const queryResult = (0, parse_1.analiseQuery)(queries, dbSchema, withSchema, []); //TODO - WHY []?
return queryResult;
}
exports.analyzeSubQuery = analyzeSubQuery;
function extractFieldsFromSubquery(subQuery, dbSchema, tableAlias) {
function extractFieldsFromSubquery(subQuery, dbSchema, withSchema, tableAlias) {
//subquery=true only for select (subquery); not for from(subquery)
// const fromColumns
const queryResult = analyzeSubQuery(subQuery, dbSchema);
const queryResult = analyzeSubQuery(subQuery, dbSchema, withSchema);
// console.log("queryResult=", queryResult);

@@ -216,0 +216,0 @@ // const tableAlias = derivadTable.tableAlias()?.text;

{
"name": "typesql-cli",
"version": "0.5.1",
"version": "0.5.2",
"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 too big to display

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