There is way to save data with SQLite from axios ? I got some strange values and warning

I try to save the data fields from the axios.get and i want to do it with SQLite but got some yellow warning and Promise with strange values .
there is way to solve my case ?

in my case i got this when i print the (dbResult) :

Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}
Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}
Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}
Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}
Promise {
  "_40": 0,
  "_55": null,
  "_65": 0,
  "_72": null,
}

[Unhandled promise rejection: Error: near "Swift": syntax error (code 1 SQLITE_ERROR[1]): , while compiling: INSERT INTO places (artist, image, title, url) VALUES (Taylor Swift, https://images-na.ssl-images-amazon.com/images/I/61McsadO1OL.jpg, Taylor Swift, https://www.amazon.com/Taylor-Swift/dp/B0014I4KH6);]
- node_modules\expo-sqlite\build\SQLite.js:36:15 in _deserializeResultSet
* [native code]:null in map
- node_modules\expo-sqlite\build\SQLite.js:16:40 in SQLiteDatabase#exec
- node_modules\promise\setimmediate\core.js:37:14 in tryCallOne
- node_modules\promise\setimmediate\core.js:123:25 in setImmediate$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:146:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:194:17 in _callImmediatesPass
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:458:30 in callImmediates
* [native code]:null in callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:407:6 in __callImmediates
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:143:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:142:17 in __guard$argument_0
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

here i create the the database and the columns :

import * as SQLite from "expo-sqlite";

const db = SQLite.openDatabase('places.db');

export const init = () => {
  const promise = new Promise((resolve, reject) => {
    db.transaction(tx => {
      tx.executeSql(
        'CREATE TABLE IF NOT EXISTS places (id INTEGER PRIMARY KEY NOT NULL, artist TEXT NOT NULL, image TEXT NOT NULL, title TEXT NOT NULL, url TEXT NOT NULL);',
        [],
        () => {
          resolve();
        },
        (_, err) => {
          reject(err);
        }
      );
    });
  });
  return promise;
};

export const insertPlace = (artist, image, title, url) => {
    const promise = new Promise((resolve, reject) => {
        db.transaction(tx => {
          tx.executeSql(
            `INSERT INTO places (artist, image ,title, url) VALUES (${artist}, ${image}, ${title}, ${url});`,
            [],
            (_, result) => {
              resolve(result);
            },
            (_, err) => {
              reject(err);
            }
          );
        });
      });
      return promise;
};

export const fetchPlaces = () => {
    const promise = new Promise((resolve, reject) => {
        db.transaction(tx => {
          tx.executeSql(
            'SELECT * FROM places',
            [],
            (_, result) => {
              resolve(result);
            },
            (_, err) => {
              reject(err);
            }
          );
        });
      });
      return promise;
};

and here i use the axios.get to get the data and after use the insertPlace function to save the fields data into the columns that in the places.db i have created but got an error as i mentioned and i dont understand my problem there .


import axios from "axios";
import { insertPlace } from "../helpers/db";

export default class WaterQualitySamplesScreen extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  getData = () => {
    axios
      .get("https://rallycoding.herokuapp.com/api/music_albums")
      .then((res) => {
        this.setState({
          data: res.data,
        });
        //  console.log(res.data);
        for (let i = 0; i < res.data.length; i++) {
          const mediaData = res.data[i];
        
            const dbResult =  insertPlace(
              mediaData.artist,
              mediaData.image,
              mediaData.title,
              mediaData.url
            );
            console.log(dbResult);

        }
      });
  };

async componentDidMount() {
    this.currentUser = await firebase.auth().currentUser;
    await this.registerForPushNotificationsAsync();

    this.getData();
  }

render() {
    return (
    ),
  };
};

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.