Skip to content

Instantly share code, notes, and snippets.

@SamuelMarks SamuelMarks/example.ts
Last active Nov 23, 2017

Embed
What would you like to do?
TypeORM
import 'reflect-metadata';
import { createConnection } from 'typeorm';
@Entity('user_tbl')
export class User {
@PrimaryColumn({ type: 'varchar' })
public username: string;
@Column({ type: 'varchar', nullable: false, select: false })
public password: string;
}
createConnection({
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "admin",
database: "test",
entities: [ User ],
synchronize: true,
logging: false
}).then(connection => {
const user0 = new User();
user0.username = 'foo';
user0.password = Math.random().toString();
connection.manager
.getRepository(User)
.save(user0)
.then(() => {
const user1 = new User();
user1.username = 'foo';
user1.password = Math.random().toString();
connection.manager
.getRepository(User)
.save(user1)
.then(() => console.info('inserted:', user1, 'over', user0, ';'))
.catch(console.error.bind(console));
})
.catch(console.error.bind(console));
}).catch(error => console.log(error));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.