Code Monkey home page Code Monkey logo

Comments (5)

simonw avatar simonw commented on June 11, 2024

Relevant code comment:

async def post(self, request):
formdata = await request.form()
csv = formdata["csv"]
# csv.file is a SpooledTemporaryFile, I can read it directly
# NOTE: this is blocking - a better implementation would run this
# in a thread.
filename = csv.filename
# TODO: Support other encodings:
reader = csv_std.reader(codecs.iterdecode(csv.file, "utf-8"))
headers = next(reader)

from datasette-upload-csvs.

simonw avatar simonw commented on June 11, 2024

I think the easiest way to do this is with the new Datasette write queue mechanism. It's not ideal for long operations but I think it's OK in this particular case to lock the database write connection for the duration of processing the CSV.

What is really like is to be able to poll for progress with the conversion and show another progress bar.

Problem there is that I don't know how many rows total are going to be imported - at least not without parking the CSV file through a first time just to count rows.

But... maybe I can use the file size trick? If I know the size of the file in bytes I can have the CSV reader work against a wrapper class which counts the number of bytes that have been read.

I would still need a mechanism for the write thread to make the progress available to be polled. How about it writes to a temporary table every few thousand bytes or so?

from datasette-upload-csvs.

simonw avatar simonw commented on June 11, 2024

I would have to be committing as I go, but I want to do that with the rows I'm inserting anyway.

from datasette-upload-csvs.

simonw avatar simonw commented on June 11, 2024

I'm feeling pretty good about this approach - opening a pull request.

from datasette-upload-csvs.

simonw avatar simonw commented on June 11, 2024

Fixed by #7

from datasette-upload-csvs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.