Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70922

Issue with creating data to sqlite database using typeorm ionic 3

$
0
0

@mohamedwahshey wrote:

I’m trying to post data into entities using typeorm, and getting this error:
ERROR Error: Uncaught (in promise): AlreadyHasActiveConnectionError: Cannot create a new connection named “default”, because connection with such name already exist and it now has an active connection session.
Error

What i’m doing is, i’m connecting to the db in app.component.ts and it works perfectly, then in another page ts file i’m trying to post a data from a form to the entity and this is where my issue is, it keeps telling me that it has already active connection, so what am i supposed to do to post data to the db with typeorm?

TS:

import { createConnection } from "ionic-orm";

    onAddEquipment() {
let options: ConnectionOptions = {
      autoSchemaSync: true,
      driver: {
        type: "websql",
        database: "bexel"
      },
      entities: [
        Equipments
      ]
      }
       createConnection(options).then(async connection => {
       let equipment = new Equipments();
       equipment = this.equipment;
      await connection.entityManager.persist(equipment);
      console.log("equipment has been saved");
    });
   }

I followed this documentation.
Someone kindly help and show me how can we write the right statement.
Note that it’s working without typeorm with native sqlite queries, so no problem with the form it’s just i don’t know how to write the statement right.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70922

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>