- Notifications
You must be signed in to change notification settings - Fork254
Feat/alasql#1457
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Feat/alasql#1457
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsclient/packages/lowcoder/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletionsclient/packages/lowcoder/src/components/ResCreatePanel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletionsclient/packages/lowcoder/src/comps/queries/httpQuery/alasqlQuery.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { QueryConfigItemWrapper, QueryConfigLabel, QueryConfigWrapper } from "components/query"; | ||
import { simpleMultiComp } from "comps/generators/multi"; | ||
import { JSONValue } from "../../../util/jsonTypes"; | ||
import { ParamsStringControl } from "../../controls/paramsControl"; | ||
import { dropdownControl } from "@lowcoder-ee/comps/controls/dropdownControl"; | ||
import { QueryResult } from "../queryComp"; | ||
import { QUERY_EXECUTION_ERROR, QUERY_EXECUTION_OK } from "@lowcoder-ee/constants/queryConstants"; | ||
import { getDynamicStringSegments, isDynamicSegment } from "lowcoder-core"; | ||
import alasql from "alasql"; | ||
import { trans } from "i18n"; | ||
const childrenMap = { | ||
databaseType: dropdownControl( | ||
[ | ||
{ label: "Data Query", value: "dataQuery" }, | ||
{ label: "Local Database", value: "localDB" }, | ||
] as const, | ||
"dataQuery" | ||
), | ||
database: dropdownControl( | ||
[ | ||
{ label: "Local Storage", value: "LOCALSTORAGE" }, | ||
{ label: "IndexedDB", value: "INDEXEDDB" }, | ||
] as const, | ||
"LOCALSTORAGE" | ||
), | ||
sql: ParamsStringControl, | ||
}; | ||
const AlaSqlTmpQuery = simpleMultiComp(childrenMap); | ||
// TODO: Support multiple queries | ||
export class AlaSqlQuery extends AlaSqlTmpQuery { | ||
override getView() { | ||
const children = this.children; | ||
const params = [ ...children.sql.getQueryParams() ]; | ||
const databaseType = children.databaseType.getView(); | ||
const selectedDB = children.database.getView(); | ||
const paramsMap: Record<string, any> = {}; | ||
params.forEach(({key, value}) => { | ||
paramsMap[key] = value(); | ||
}); | ||
const sqlQuery = children.sql.children.text.unevaledValue.replace(/ +/g, ' '); | ||
const isCreateDBQuery = sqlQuery.toUpperCase().startsWith('CREATE DATABASE'); | ||
return async (p: { args?: Record<string, unknown> }): Promise<QueryResult> => { | ||
try { | ||
let result: JSONValue; | ||
const timer = performance.now(); | ||
if (databaseType === 'localDB' && isCreateDBQuery) { | ||
const updatedQuery = `${sqlQuery.slice(0, 6)} ${selectedDB} ${sqlQuery.slice(6)}`; | ||
const tableName = updatedQuery.split(' ').pop()?.replace(';', ''); | ||
result = alasql(updatedQuery); | ||
result = alasql(`ATTACH ${selectedDB} DATABASE ${tableName};`); | ||
} else { | ||
let segments = getDynamicStringSegments(sqlQuery); | ||
let dataArr: any = []; | ||
segments = segments.map((segment) => { | ||
if (isDynamicSegment(segment)) { | ||
const key = segment.replace('{{','').replace('}}',''); | ||
dataArr.push(paramsMap[key]); | ||
return '?'; | ||
} | ||
return segment; | ||
}) | ||
result = alasql(segments.join(' '), dataArr); | ||
} | ||
return { | ||
data: result as JSONValue, | ||
code: QUERY_EXECUTION_OK, | ||
success: true, | ||
runTime: Number((performance.now() - timer).toFixed()), | ||
}; | ||
} catch (e) { | ||
return { | ||
success: false, | ||
data: "", | ||
code: QUERY_EXECUTION_ERROR, | ||
message: (e as any).message || "", | ||
}; | ||
} | ||
}; | ||
} | ||
propertyView(props: { datasourceId: string }) { | ||
return <PropertyView {...props} comp={this} />; | ||
} | ||
} | ||
const PropertyView = (props: { comp: InstanceType<typeof AlaSqlQuery>; datasourceId: string }) => { | ||
const { comp } = props; | ||
const { children } = comp; | ||
return ( | ||
<> | ||
<QueryConfigWrapper> | ||
<QueryConfigLabel>{trans("query.databaseType")}</QueryConfigLabel> | ||
<QueryConfigItemWrapper> | ||
{children.databaseType.propertyView({ | ||
styleName: "medium", | ||
width: "100%", | ||
})} | ||
</QueryConfigItemWrapper> | ||
</QueryConfigWrapper> | ||
{children.databaseType.getView() === 'localDB' && ( | ||
<QueryConfigWrapper> | ||
<QueryConfigLabel>{trans("query.chooseDatabase")}</QueryConfigLabel> | ||
<QueryConfigItemWrapper> | ||
{children.database.propertyView({ | ||
styleName: "medium", | ||
width: "100%", | ||
})} | ||
</QueryConfigItemWrapper> | ||
</QueryConfigWrapper> | ||
)} | ||
<QueryConfigWrapper> | ||
<QueryConfigItemWrapper> | ||
{children.sql.propertyView({ | ||
placement: "bottom", | ||
placeholder: "SELECT * FROM users WHERE user_id = {{userId}}::uuid", | ||
styleName: "medium", | ||
language: "sql", | ||
enableMetaCompletion: true, | ||
})} | ||
</QueryConfigItemWrapper> | ||
</QueryConfigWrapper> | ||
</> | ||
); | ||
}; |
1 change: 1 addition & 0 deletionsclient/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletionsclient/packages/lowcoder/src/comps/queries/resourceDropdown.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsclient/packages/lowcoder/src/comps/queries/sqlQuery/SQLQuery.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsclient/packages/lowcoder/src/constants/datasourceConstants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionclient/packages/lowcoder/src/constants/libConstants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export const libNames = new Set(["uuid", "numbro", "Papa", "supabase", "alasql"]); |
5 changes: 4 additions & 1 deletionclient/packages/lowcoder/src/constants/queryConstants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsclient/packages/lowcoder/src/global.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -9,5 +9,6 @@ declare global { | ||
numbro: any; | ||
Papa: any; | ||
uuid: any; | ||
alasql: any; | ||
} | ||
} |
3 changes: 3 additions & 0 deletionsclient/packages/lowcoder/src/i18n/locales/en.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsclient/packages/lowcoder/src/index.sdk.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletionsclient/packages/lowcoder/src/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
57 changes: 56 additions & 1 deletionclient/yarn.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.