I have been trying for a few days to create a connection with my entities on TypeORM in React Native, but to no avail.This is the code that create the connection.
import {createConnection, getManager, getConnection} from 'typeorm/browser';import MessageSent from '../dbmodels/MessageSent';import Test from '../dbmodels/Test';import User from '../dbmodels/User';import UserEquipment from '../dbmodels/UserEquipment';export default class DBManager { static async connectDB() { return await createConnection({ type: 'react-native', database: 'VRU', location: 'default', logging: ['error', 'query', 'schema'], synchronize: true, entities: [MessageSent, Test, User, UserEquipment], }); } static async saveMessageSent(messageSent) { console.log('OPTIONS: '+ JSON.stringify(getConnection().options)); await getManager().save(messageSent); }}
My MessageSent entity is:
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne} from 'typeorm';import Test from './Test'@Entity()export default class MessageSent { @PrimaryGeneratedColumn('integer') id: number; @Column('varchar',{ length: 20 }) pco_level: string; @Column('integer') time_generation_started: number; @Column('integer') time_generation_ended: number; @Column('integer') time_sent: number; @Column('varchar') content: string //TODO ajustar ao tipo pedido pelo CTAG? @Column('varchar',{ length: 10 }) message_type: string; @Column('varchar',{ length: 20 }) message_encoding: string; @Column('varchar',{ length: 10 }) message_status: string; @Column('varchar') message_error: string; @Column('integer') message_rate: number; @Column('varchar', {length:10}) flow_direction: string; //Pode ser um enum //NOTA: A localização foi separada em dois campos porque o TypeORM não suporta os campos geográficos do SQLite (SpatiaLite) e também porque as locations estão definidos como dois campos na documentação de logs @Column('Double') latitude: number; @Column('Double') longitude: number; @Column('Double') speed: number; @Column('Double') acceleration: number; @Column('varchar',{ length: 10 }) communication_protocol: string; @Column('varchar',{ length: 10 }) security_protocol: string; @Column('integer') battery_level: number; @Column('integer') battery_consumption: number; @Column('integer') cpu_usage: number; @Column('integer') ram_usage: number; @Column('boolean') app_in_foreground: boolean; @Column('Test') @ManyToOne(type => Test, test => test.messagesSent) //Ver como fazer as chaves estrangeiras test: Test;}
Everything seems ok. I have checked and rechecked the paths and tried everything I could think of, but the console.log above, when the saveMessageSent function is invoked, returns the following result:
OPTIONS: {"type":"react-native","database":"VRU","location":"default","logging":["error","query","schema"],"synchronize":true,"entities":[null,null,null,null]}
And, of course , the line that saves de entity returns de error:
Possible Unhandled Promise Rejection (id: 0): EntityMetadataNotFound: No metadata for "MessageSent" was found.
Any help would be greatly appreciated.
Thank you.