-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #1883 + Typescript Plugin Improvements #1986
base: develop
Are you sure you want to change the base?
Conversation
Enhance Readability and Documentation, Type Aliases: Introduced type aliases. Increased Type Safety: Refined types for better accuracy, especially in callback signatures and function definitions.
The improved code includes updates for readability, maintainability, and modern JavaScript practices. Key changes include using arrow functions and template literals for cleaner syntax, and optional chaining to streamline property access where values may be undefined. Destructured assignments enhance readability, and constants are used for immutability where applicable. Additionally, inline comments clarify each change for easy reference, while error handling improvements ensure the code remains robust and clear. These changes collectively modernize the codebase while preserving its original functionality and use cases.
Spread Syntax in Function Arguments: Used (...args) to collect arguments in stdfn.SPRINTF for better readability and flexibility. Template Literals and Arrow Functions: Simplified type-specific formatter functions with arrow functions for consistency and clarity.
I love it. Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments.
}); | ||
}; | ||
|
||
// Regular expression updated with comments for readability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comments?
|
||
stdfn.SPRINTF.H = (ins, x) => { | ||
let cleanIns = String(ins).replace(/,/g, ''); // Remove commas for number parsing | ||
x[2] = x[2] === '-' ? '+' : '-'; // Adjust alignment for string output |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that comment is correct?
@@ -1,21 +1,18 @@ | |||
/* | |||
// | |||
// CREATE VERTEX for AlaSQL | |||
// Date: 21.04.2015 | |||
// (c) 2015, Andrey Gershun | |||
// Date: 04/11/2024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not change the date.
// Date: 21.04.2015 | ||
// (c) 2015, Andrey Gershun | ||
// Date: 04/11/2024 | ||
// (c) 2015, Andrey Gershu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dont change the surname of the author...
yy.CreateVertex = function (params) { | ||
return Object.assign(this, params); | ||
}; | ||
yy.CreateVertex = (params) => Object.assign(this, params); // Updated to arrow function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dont leave comments like this as it will not make sense in the future
// todo: SET | ||
// todo: CONTENT | ||
// todo: SELECT | ||
// Future TODOs: SET, CONTENT, SELECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the original comments please
var s = 'this.queriesfn[' + (this.queriesidx - 1) + '](this.params,null,' + context + ')'; | ||
return s; | ||
yy.CreateEdge.prototype.toJS = (context) => { | ||
return `this.queriesfn[${this.queriesidx - 1}](this.params,null,${context})`; // Template literal for consistency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove comment
|
||
// Optional functions | ||
namefn?.(edge); | ||
namefn?.(edge); // Optional chaining |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove comment
@@ -196,7 +157,7 @@ yy.CreateGraph.prototype.execute = function (databaseid, params, cb) { | |||
if (g.class !== undefined) e.$class = g.class; | |||
|
|||
let db = alasql.databases[databaseid]; | |||
e.$id = e.$id !== undefined ? e.$id : db.counter++; | |||
e.$id = e.$id ?? db.counter++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
} | ||
} | ||
return undefined; | ||
return Object.values(alasql.databases[alasql.useid].objects).find((obj) => obj.name === name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We simply cant be making copies of all the data in an object for operations like this. We need to keep the original or find a way where we can search the original object without making a copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need comments to be related to what the code does (if needed at all) - not why something was changed.
if (typeof g.json !== 'undefined') { | ||
extend(v, new Function('params,alasql', 'var y;return ' + g.json.toJS())(params, alasql)); | ||
const db = alasql.databases[databaseid]; | ||
const v = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too many changes. And I dont feel like this will provide the same result. where. is the .prop aspect?
res.push(v.$id); | ||
return v; | ||
} | ||
}; | ||
yy.CreateGraph.prototype.compile1 = function (databaseid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we just remove all of this?!?
yy.CreateDatabase = function (params) { | ||
return Object.assign(this, params); | ||
}; | ||
yy.CreateDatabase = (params) => Object.assign(this, params); // Updated to arrow function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep regular functions for high level so they remain informative in the stack trace
yy.CreateDatabase.prototype.toString = function () { | ||
let s = 'CREATE '; // Ensure there's a space after CREATE | ||
let s = 'CREATE '; // Added space after 'CREATE' for clarity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert comment
if (this.engineid) s += `${this.engineid} `; | ||
s += 'DATABASE '; | ||
if (this.ifnotexists) s += 'IF NOT EXISTS '; | ||
s += `${this.databaseid} `; | ||
|
||
if (this.args && this.args.length > 0) { | ||
if (this.args?.length) { // Optional chaining for args presence check |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove comment
* | ||
* @type {tableLookUp} | ||
* @memberof database | ||
* Collection of tables in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this comment updated?
* | ||
* @type {any[]} | ||
* @memberof table | ||
* Array of data rows within the table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No value in the old comment?
* | ||
* @type {databaseLookUp} | ||
* @memberof AlaSQL | ||
* Dictionary of databases managed by AlaSQL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not the type notation?
* Equivalent to alasql('USE '+databaseid). This will change the current | ||
* database to the one specified. This will update the useid property and | ||
* the tables property. | ||
* Switches the current database context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the context of the old comment
* | ||
* @type {string} | ||
* @memberof AlaSQL | ||
* Current active database ID. Defaults to 'alasql' if none specified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the type notation
Looks like the tests are not running. Please make sure to do a |
Key changes include using arrow functions and template literals for cleaner syntax, and optional chaining to streamline property access where values may be undefined. Destructured assignments enhance readability, and constants are used for immutability where applicable. Additionally, inline comments clarify each change for easy reference, while error handling improvements ensure the code remains robust and clear. These changes collectively modernize the codebase while preserving its original functionality and use cases