mywaydogs / MyWay-server

MIT License
3 stars 2 forks source link

create a script that will populate empty DB by sync and insert queries #1

Closed Flexusaurs closed 2 years ago

Flexusaurs commented 2 years ago

a script was written - but i keep getting this error

import { Dog } from "./dogs/entities/dog.entity";
^^^^^^

SyntaxError: Cannot use import statement outside a module

right now, it should work properly - based on an assumption that you've just created a blank local psg db as a development environment it will push basic dog data/ mock data query for testing purposes. the only problem is the import issue that occur mid compilation

import { Dog } from "./dogs/entities/dog.entity";
import { createConnection } from "typeorm";
export function dbpop(){

createConnection({ //TODO: export to .ENV
  *your credentials go here*
    ],
    synchronize: true,
}).then(async connection => {
    // here you can start to work with your entities
 let dog = new Dog;
 dog.name = "test doggie";
 dog.birthDate = null;
 dog.breed = "a test breed";
 dog.socialization = "test";
 dog.litterSeparation = "test";
 dog.origin = "test";
 dog.healthIssues = "none";
 dog.foodDrive = "Medium";
 dog.preyDrive = "High";
 dog.currentSchedule = "none";
 dog.energyLevel = "Low";
 dog.homeBehaviours = "test";
 dog.outsideBehaviours = "test";
 dog.customerId = 1;

 const dog_1 = await connection.manager
        .save(dog);
    console.log("dog has been saved", dog_1.id);

}).catch(error => console.log(error));
}
Flexusaurs commented 2 years ago

fixed, pushing to branch :)