docs: fix javascript usage examples (#7031)

This commit is contained in:
Ed Colvin 2021-01-12 03:26:06 -09:00 committed by GitHub
parent ddd8cbcdf6
commit 4ed1c4bf8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 13 deletions

View File

@ -58,7 +58,9 @@ typeorm.createConnection({
##### entity/Category.js
```typescript
module.exports = {
var EntitySchema = require("typeorm").EntitySchema;
module.exports = new EntitySchema({
name: "Category", // Will use table name `category` as default behaviour.
tableName: "categories", // Optional: Provide `tableName` property to override the default behaviour for table name.
columns: {
@ -68,16 +70,18 @@ module.exports = {
generated: true
},
name: {
type: "string"
type: "varchar"
}
}
};
});
```
##### entity/Post.js
```typescript
module.exports = {
var EntitySchema = require("typeorm").EntitySchema;
module.exports = new EntitySchema({
name: "Post", // Will use table name `post` as default behaviour.
tableName: "posts", // Optional: Provide `tableName` property to override the default behaviour for table name.
columns: {
@ -87,7 +91,7 @@ module.exports = {
generated: true
},
title: {
type: "string"
type: "varchar"
},
text: {
type: "text"
@ -101,7 +105,7 @@ module.exports = {
cascade: true
}
}
};
});
```
You can checkout this example [typeorm/javascript-example](https://github.com/typeorm/javascript-example) to learn more.

View File

@ -17,7 +17,10 @@ typeorm
password: "admin",
database: "test",
synchronize: true,
entitySchemas: [require("./entity/Post"), require("./entity/Category")]
entities: [
require("./entity/Post"),
require("./entity/Category")
]
})
.then(function(connection) {
var category1 = {
@ -54,7 +57,9 @@ typeorm
##### entity/Category.js
```typescript
module.exports = {
var EntitySchema = require("typeorm").EntitySchema;
module.exports = new EntitySchema({
name: "Category",
columns: {
id: {
@ -63,16 +68,18 @@ module.exports = {
generated: true
},
name: {
type: "string"
type: "varchar"
}
}
};
});
```
##### entity/Post.js
```typescript
module.exports = {
var EntitySchema = require("typeorm").EntitySchema;
module.exports = new EntitySchema({
name: "Post",
columns: {
id: {
@ -81,7 +88,7 @@ module.exports = {
generated: true
},
title: {
type: "string"
type: "varchar"
},
text: {
type: "text"
@ -95,7 +102,7 @@ module.exports = {
cascade: true
}
}
};
});
```
您可以查看此示例[typeorm/javascript-example](https://github.com/typeorm/javascript-example)以了解更多信息。