question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

object converted automatically with toString()

See original GitHub issue

Issue type:

[X] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [X] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem: I have item data with LatLng coordinate pairs stored in a column, and it comes back from my API in JSON format: item: {id: 3, latlngs: {lat: 123, lng: 456}

I have tried to use the @BeforeInsert() method to convert the column data with JSON.stringify(latlngs) but this isn’t being processed accordingly, and i keep getting the yellowbox.js error in the console with the message:

addStatement - parameter of type <object> converted to string using toString()

I had this working before by manually extracting the item data via a flatMap()and transforming each individual item’s latlng via JS via JSON.stringify() but I am unsure how to inject this behavior when I am doing cascading inserts for these entities.

any guidance/help would be greatly appreciated! this ORM is fantastic and I am enjoying and greatly benefiting from using it thus far, thank you to all the maintainers and developers on this project!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
silentroachcommented, Oct 2, 2019
  @Column({
    type: "varchar",
    nullable: true,
    transformer: {
      // used to deserialize your data from db field value
      from(val: string) {
        return JSON.parse(val);
      },
      // used to serialize your data to db field
      to(val: object) {
        return JSON.stringify(val);
      }
    }
  })
  latlngs: object;
0reactions
csdalcommented, Aug 18, 2022

(a comment for future references, who searched for this error)

In react-native-sqlite-storage: ^6.0.1, I experience this:

 WARN  addStatement - parameter of type <object> converted to string using toString()

Solved by this:

values.toString()

Example code (Solution):

const addOne = async (db, {firstName, lastName})=>{
  const values = [firstName, lastName].toString(); // 👈👈 add .toString() after array-based values
  const statement = `INSERT INTO tableName (firstName, lastName) VALUES (?,?)`;
  await db.execute(statement, values);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Object.prototype.toString() - JavaScript - MDN Web Docs
The toString() method returns a string representing the object. This method is meant to be overridden by derived objects for custom type ...
Read more >
How to prevent an Object being cast to a String automatically
If I use this class on a method with a String argument the java compiler will automatically convert this to a String object...
Read more >
Java's automatic conversion rule for number ⇒ string
User-controlled conversion of objects into String representation - toString() · Java provides an automatic conversion feature when the + operator is used between ......
Read more >
Object.ToString Method (System)
Object.ToString is the major formatting method in the .NET Framework. It converts an object to its string representation so that it is suitable...
Read more >
Java: Converting Anything to String
Method toString is already defined. When Java needs to convert an object to a String, it calls the object's toString() method. Because every...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found