Save table to mysql database

132 views
Skip to first unread message

mfrod...@gmail.com

unread,
Jul 11, 2015, 3:58:54 PM7/11/15
to handso...@googlegroups.com
Hello,

I've seen that this great software is able to insert the contents of a table to a SQL database, and also read the same contents from the database.

However, during my experience, I had to do the SQL query manually. Is there any method that iterates over the javascript with the array of changed elements and prepares a SQL statement?

I've seen some examples, but not with the full scope, with the part of the SQL.

Tks!

Ivan Ogasawara

unread,
Jul 15, 2015, 11:31:04 AM7/15/15
to mfrod...@gmail.com, handso...@googlegroups.com
Hi,

I'm using python to do that ... maybe this is not the best approach .. but at this moment it's ok ..
I'm loading the json data using pandas .. 
next I iterate over each row of my dataframe .. and put the data on my sqlalchemy model.

example:

# using pandas
df = pd.DataFrame(request.get_json('data')['data'], dtype = float)
# update
for k, v in df.iterrows():
    # using SQLAlchemy Model (declarative base)
    data = DataModel.query.filter_by(id=v.id).first()
    data.update(commit=True, **v.to_dict())

my best regards,

Ivan


--
You received this message because you are subscribed to the Google Groups "Handsontable" group.
To unsubscribe from this group and stop receiving emails from it, send an email to handsontable...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages