Skip to content

Support CSV data import#25

Merged
Brayden merged 1 commit intomainfrom
bwilmoth/import-csv
Oct 18, 2024
Merged

Support CSV data import#25
Brayden merged 1 commit intomainfrom
bwilmoth/import-csv

Conversation

@Brayden
Copy link
Member

@Brayden Brayden commented Oct 16, 2024

Purpose

Allow users to import data from either part of the POST body as a JSON object, or from a .csv file. The data will attempted to be inserted row by row, reporting any errors back in the response and the failure reason, into the specified table as indicated in the URL.

Tasks

  • Expose an endpoint that supports both FILE and CSV upload
  • Attempt to insert new data into provided table (table name in URL)
  • On failure of insert, add to array to return as final result

Verify

Failed Entry

cURL

curl --location 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/import/csv/users' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-Type: application/json' \
--data '{
  "data": "column1,column2\nvalue1,value2\nvalue3,value4",
  "columnMapping": {
    "column1": "database_column1",
    "column2": "database_column2"
  }
}'

Response:

{"result":{"message":"Imported 0 out of 2 records successfully. 2 records failed.","failedStatements":[{"statement":"INSERT INTO users (database_column1, database_column2) VALUES (?, ?)","error":"Unknown error"},{"statement":"INSERT INTO users (database_column1, database_column2) VALUES (?, ?)","error":"Unknown error"}]}}

Successful Entry

cURL

curl --location 'https://starbasedb.YOUR-IDENTIFIER.workers.dev/import/csv/users' \
--header 'Authorization: Bearer ABC123' \
--header 'Content-Type: application/json' \
--data '{
  "data": "name,email\nJohn Doe,[email protected]\nJane Smith,[email protected]",
  "columnMapping": {
    "name": "name",
    "email": "email"
  }
}'

Response:

{"result":{"message":"Imported 2 out of 2 records successfully. 0 records failed.","failedStatements":[]}}

Before

After

@Brayden Brayden self-assigned this Oct 16, 2024
@Brayden Brayden added the enhancement New feature or request label Oct 16, 2024
@Brayden Brayden merged commit 721867f into main Oct 18, 2024
@Brayden Brayden deleted the bwilmoth/import-csv branch October 18, 2024 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant