DataSource
1
DataSourceOptions
Entity
3
@Column
@PrimaryColumn()
@PrimaryGeneratedColumn()
save()
4Your interaction with the database is only possible once you setup a DataSource
. TypeORM's DataSource
holds your database connection settings and establishes initial database connection or connection pool depending on the RDBMS you use. ↩
synchronize
- Indicates if database schema should be auto created on every application launch. Be careful with this option and don't use this in production - otherwise you can lose production data. This option is useful during debug and development. As an alternative to it, you can use CLI and run schema:sync command. Note that for MongoDB database it does not create schema, because MongoDB is schemaless. Instead, it syncs just by creating indices. ↩
Entity is a class that maps to a database table (or collection when using MongoDB). You can create an entity by defining a new class and mark it with @Entity()
: ↩
When you save entities using save
it always tries to find an entity in the database with the given entity id (or ids). If id/ids are found then it will update this row in the database. If there is no row with the id/ids, a new row will be inserted. ↩