live-query-mysql
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -64,2 +64,7 @@ "use strict"; | ||
continue; | ||
const tableMap = ast.from.reduce((r, from) => { | ||
r[from.as] = from.table; | ||
r[from.table] = from.table; | ||
return r; | ||
}, {}); | ||
for (const from of ast.from) { | ||
@@ -70,3 +75,3 @@ if (from["type"] == "dual") | ||
name: from.table, | ||
affects: trackExpression_1.createTrackAffects(ast.where, params), | ||
affects: trackExpression_1.createTrackAffects(ast.where, tableMap, params), | ||
}); | ||
@@ -73,0 +78,0 @@ } |
import { Row } from "binlog-triggers-mysql"; | ||
export declare type TrackExpression = (row: Row, tableName: string) => boolean; | ||
export declare function createTrackAffects(where: any, params: any): TrackExpression; | ||
export declare type TableMap = { | ||
[alias: string]: string; | ||
}; | ||
export declare function createTrackAffects(where: any, tableMap: TableMap, params: any[]): TrackExpression; | ||
export declare function wrapPlaceholders(s: any): string; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const log = require("loglevel"); | ||
function createTrackAffects(where, params) { | ||
function createTrackAffects(where, tableMap, params) { | ||
if (!where) | ||
@@ -11,3 +11,3 @@ return () => true; | ||
try { | ||
impl = expr(where, params); | ||
impl = expr(where, tableMap, params); | ||
} | ||
@@ -34,7 +34,7 @@ catch (e) { | ||
// parsing based on https://github.com/taozhi8833998/node-sql-parser/blob/master/ast/postgresql.ts | ||
function expr(node, params) { | ||
function expr(node, tableMap, params) { | ||
// console.log(node) | ||
switch (node.type) { | ||
case "binary_expr": | ||
return binary_expr(node, params); | ||
return binary_expr(node, tableMap, params); | ||
case "string": | ||
@@ -54,5 +54,5 @@ if (node.value.startsWith(placeholderPrefix)) { | ||
case "column_ref": | ||
return column_ref(node); | ||
return column_ref(node, tableMap); | ||
case "expr_list": | ||
return expr_list(node, params); | ||
return expr_list(node, tableMap, params); | ||
default: | ||
@@ -64,5 +64,6 @@ // will be catched, and all rows matched | ||
} | ||
function column_ref(node) { | ||
function column_ref(node, tableMap) { | ||
return (row, tableName) => { | ||
if (node.table && node.table != tableName) { | ||
const table = Object.values(tableMap).indexOf(node.table) >= 0 ? node.table : tableMap[node.table]; | ||
if (table != tableName) { | ||
throw new Error(`Can't refer column ${node.table}.${node.column}`); | ||
@@ -73,4 +74,4 @@ } | ||
} | ||
function expr_list(node, params) { | ||
const items = node.value.map((v) => expr(v, params)); | ||
function expr_list(node, tableMap, params) { | ||
const items = node.value.map((v) => expr(v, tableMap, params)); | ||
return (row, tableName) => { | ||
@@ -80,5 +81,5 @@ return items.map((i) => i(row, tableName)); | ||
} | ||
function binary_expr(node, params) { | ||
const left = expr(node.left, params); | ||
const right = expr(node.right, params); | ||
function binary_expr(node, tableMap, params) { | ||
const left = expr(node.left, tableMap, params); | ||
const right = expr(node.right, tableMap, params); | ||
return (row, tableName) => { | ||
@@ -85,0 +86,0 @@ const leftValue = left(row, tableName); |
{ | ||
"name": "live-query-mysql", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"main": "dist/index.js", | ||
@@ -20,3 +20,4 @@ "types": "dist/index.d.ts", | ||
"build": "tsc", | ||
"test": "mocha -r ts-node/register ./tests/**/*.ts" | ||
"test": "mocha -r ts-node/register ./tests/**/*.ts", | ||
"prepublish": "yarn build" | ||
}, | ||
@@ -23,0 +24,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23175
321