I am not sure why doesconsole.log(exercise)
in my method extractData()
returns undefined? I think I have already did the entity classes and migration files.
Snippet of App.tsx
const AppDataSource = new DataSource({ type: "expo", database: "GymTracker", driver: require("expo-sqlite"), entities: [Exercise, MajorMuscles, SetOfSets], migrations: ['migrations/test.ts'], synchronize: false, migrationsRun: true, logging: true,});AppDataSource.initialize() .then(() => { console.log("Data Source has been initialized"); asyncDBTest(); }) .catch((err) => { console.error(err +"Error during data source init.") });async function asyncDBTest() { console.log("entered asynDBTest"); await AppDataSource.runMigrations() .then(() => extractText()) .catch((err) => console.log(err));}async function extractText() { console.log("entered extractText"); const repo = AppDataSource.getRepository(Exercise); const exercise = await repo.find().then(() => { console.log(exercise); });}
Exercise.tsx
import {Entity,Column, PrimaryGeneratedColumn} from "typeorm/browser";import "reflect-metadata";@Entity({name:"exercise"})export class Exercise{ @PrimaryGeneratedColumn("uuid") id!:number; @Column("text") name!: Text; @Column("text") notes:Text; @Column('text') imageJSON:Text;}
test.tsx, my migration file
import { MigrationInterface, QueryRunner } from "typeorm"export class test1657016189203 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise<void> { ... await queryRunner.manager.query('INSERT INTO exercise (name) VALUES ("Conventional Deadlift")',); await queryRunner.manager.query('INSERT INTO exercise (name) VALUES ("Romanian Deadlift")',); await queryRunner.manager.query('INSERT INTO exercise (name) VALUES ("Straight-legged Deadlift")',); await queryRunner.manager.query('INSERT INTO exercise (name) VALUES ("Sumo Deadlift")',); ... } public async down(queryRunner: QueryRunner): Promise<void> { }}