Code Monkey home page Code Monkey logo

Comments (5)

Rjtsahu avatar Rjtsahu commented on May 22, 2024 1

This is happening as a socket cannot be created to establish a connection ( for same reason you cannot use library such as requests). The web assembly doesn't support native sockets AFAIK

from pyscript.

MarcSkovMadsen avatar MarcSkovMadsen commented on May 22, 2024 1

Would it be an idea to repurpose this to documentation describing how to interact with databases?

from pyscript.

marimeireles avatar marimeireles commented on May 22, 2024

Would it be an idea to repurpose this to documentation describing how to interact with databases?

This is definitely an interesting topic for the "How to" part of the docs.
I guess we can repurpose this issue to point to that.
In case anyone wants to tackle it, feel free to reach out to me.
We have docs on how to build the docs, and good "how to" examples that were contributed by the community in the past.
Maybe one of the docs that'd be relevant to this issue is: How to make HTTP requests using PyScript, in pure Python

from pyscript.

hemangjoshi37a avatar hemangjoshi37a commented on May 22, 2024

Hi @PartikIITD and everyone,

As mentioned earlier, using sockets directly to connect to databases like MySQL is not possible in the current setup due to the limitations of web assembly. However, you can still interact with databases using alternative methods, such as making API calls to a server-side script that handles the database operations.

For instance, you can create a server-side script (using Flask, Django, or any other preferred framework) that interacts with the MySQL database, and then expose an API endpoint to perform the required database operations. Next, use PyScript to make HTTP requests (GET, POST, etc.) to these API endpoints to perform the desired tasks.

Here's a high-level outline of the steps:

  1. Develop a server-side script (e.g., in Python, PHP, or Node.js) that connects to the MySQL database and performs the necessary operations.
  2. Expose API endpoints for the server-side script to perform CRUD operations on the database.
  3. Use PyScript to make HTTP requests to the API endpoints to interact with the database indirectly.

I hope this helps! Please let me know if you have any questions or need further assistance.

from pyscript.

WebReflection avatar WebReflection commented on May 22, 2024

PyScript works on the browser, where it's hard to install MySQL or PostgreSQL in any meaningful way so sockets and libraries to connect via sockets or REST API is needed.

However, I think sqlite would work out of the box, but it would likely be an in-memory (hence volatile) solution.

There are JS libraries that persist SQLite on the browser and maybe there's something in the Python Web world too, but this is how it works and there's no action for us to take directly.

Closing for the mentioned reason.

from pyscript.

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.