Skip to content

Remove unnecessary functions#2

Merged
Brayden merged 2 commits intomainfrom
bwilmoth/remove-unused-functions
Sep 30, 2024
Merged

Remove unnecessary functions#2
Brayden merged 2 commits intomainfrom
bwilmoth/remove-unused-functions

Conversation

@Brayden
Copy link
Member

@Brayden Brayden commented Sep 30, 2024

Previously was taking the approach of manually escaping SQL based on params input, but seems I simply missed that you can optionally pass in params as a second input to .exec but only when it exists. Otherwise it will fail if you pass in undefined.

Testing SQL cURL:

curl --location --request POST 'https://starbasedb.brayden-b8b.workers.dev/query' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer ABC123' \
--data-raw '{
    "sql": "SELECT * FROM artist WHERE artistid=$1;",
    "params": [123]
}'

Worth noting that the following code would not work:

cursor = this.sql.exec(sql, params ?? []);

If the params array is valid but empty, it still breaks. It must be like this:

if (params && params.length) {
    cursor = this.sql.exec(sql, params);
} else {
    cursor = this.sql.exec(sql);
}

@Brayden Brayden merged commit a6fa0d0 into main Sep 30, 2024
@Brayden Brayden deleted the bwilmoth/remove-unused-functions branch September 30, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant