Skip to content
Open

y #1533

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions test45.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var typeorm = require("typeorm");
var EntitySchema = typeorm.EntitySchema;

const Users = require("./entity/Users")

typeorm.createConnection({
name: "mysql",
type: "mysql",
host: "localhost",
port: 3306,
username: "root",
password: "root",
database: "acme",
synchronize: true,
"logging": true,
entities: [
new EntitySchema(Users)
]
}).then(() => {

const dbConnection = typeorm.getConnection('mysql')

const repo = dbConnection.getRepository("Users")
return repo
}).then((repo) => {

console.log('Seeding 2 users to MySQL users table: Liran (role: user), Simon (role: admin')
const inserts = [
repo.insert({
name: "Liran",
address: "IL",
role: "user"
}),
repo.insert({
name: "Simon",
address: "UK",
role: "admin"
})
];

return Promise.all(inserts)
}).catch((err) => {
console.error('failed connecting and seeding users to the MySQL database')
console.error(err)
})