Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function createMyConnection() {
- await createConnection({
- driver: {
- type: "postgres",
- host: "myHost",
- port: 5432,
- username: "myUsername",
- password: "mypassword",
- database: "mydatabase"
- },
- entities: [
- Photo, PhotoMetadata, Author, Album
- ],
- autoSchemaSync: true,
- });
- let connection = getConnectionManager().get();
- let photo = new Photo();
- photo.name = "Me and Bears";
- photo.description = "I am near polar bear222";
- photo.fileName = "photo-with-bears.jpg";
- photo.views = 1;
- photo.isPublished = true;
- let metadata = new PhotoMetadata();
- metadata.height = 640;
- metadata.width = 480;
- metadata.compressed = true;
- metadata.comment = "cybershoot";
- metadata.orientation = "portait";
- photo.metadata = metadata;
- let author = new Author();
- author.name = 'Kaveh';
- photo.author = author;
- let album = new Album();
- album.name = 'MyAlbum1';
- let album2 = new Album();
- album.name = 'MyAlbum2';
- photo.albums = [album, album2];
- connection.entityManager
- .persist(photo)
- .then(p => {
- console.log("Photo has been saved");
- connection.close();
- })
- .catch(() => {
- connection.close();
- });
- }
- createMyConnection();
- (node:540) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): error: syntax error at or near ")"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement