Skip to navigation
Example to save data from a MySQL database to a couchdb database
29.11.23
Example to save data from a MySQL database to a couchdb database ```python #! /usr/bin/env python import pymysql import sortedcontainers import couchdb2 import hashlib # https://gtts.readthedocs.io/en/latest/module.html#gtts.tts.gTTS # https://pymssql.readthedocs.io/en/stable/ref/pymssql.html#cursor-class # How to save data from a mysql database to a couchdb with python db=pymysql.connect(host="localhost" ,user="USERNAME" ,password="MYPASS" ,database="DBNAME") c=db.cursor(pymysql.cursors.DictCursor) sql= """ SELECT p1.phrase as en ,p1.sound_file as en_sound ,p2.phrase as th ,p2.sound_file as th_sound FROM `phrase_phrase` AS pp LEFT JOIN phrase as p1 ON pp.phrase1 = p1.id LEFT JOIN phrase as p2 ON pp.phrase2 = p2.id """ #print(sql) c.execute(sql) server = couchdb2.Server(href="https://cb.COUCHDB.com", username="ADMINUSER", password="PASSWORD", use_session=True, ca_file=None) db = server.get("DBNAME") docs = [] for k,i in enumerate(c.fetchall()): doc = sortedcontainers.SortedDict() doc["_id"] = hashlib.sha256(str(i["en"]).encode('utf-8')).hexdigest()[:16] doc["en"] = sortedcontainers.SortedDict({ "phrase" : i["en"], "phrase_sound" : i["en_sound"] }) doc["th"] = sortedcontainers.SortedDict({ "phrase" : i["th"], "phrase_sound" : i["th_sound"] }) print(k) print(doc) db.put(doc) ```
https://couchdb.apache.org/
Reply
Anonymous
Information Epoch 1735241411
Solving the next 5% probably costs more than the previous 90%.
Home
Notebook
Contact us