npm install polaris-typeorm
This library provides support and wrappers for typeorm functionality. [Typeorm]
Through this method we can create the polaris connection to our DB on top of typeorm.
const connection: PolarisConnection = await createPolarisConnection(
connectionOptions,
polarisGraphQLLogger,
);
The createPolarisConnection
method receives:
ConnectionOptions
fromtypeorm
(see documentation on typeorm)AbstractPolarisLogger
from@enigmatis/polaris-logs
, implemented byPolarisGraphQLLogger
from@enigmatis/polaris-graphql-logger
or byPolarisLogger
from@enigmatis/polaris-logs
This class extends the typeorm Connection
class.
Through a PolarisConnection
we will have access to the PolarisRepository
.
const authorRepo: PolarisRepository = connection.getRepository(Author);
This class extends the typeorm Repository
class.
In addition to the types required by typeorm functions in this class, we added a requested field in each function we've overridden.
That field is PolarisGraphQLContext
from @enigmatis/polaris-common
which we must have for the filters and additions answering the api standards.
await authoRepo.find(context, { where: {name:"chen"}}));
This class extends the typeorm ConnectionManager
. Using the next method you will get your polarisConnection
from every place in the code.
const connection: PolarisConnection = getPolarisConnectionManager().get();
This class represents the base entity that all of your polaris entities should inherit from. It provides default fields for your entity :
- createdBy(string - Optional) - this field indicates who created the entity.
- creationTime - when was the entity created.
- lastUpdateBy(string - Optional) - this field indicates who last updated the entity.
- lastUpdateTime - when was the entity last updated.
- dataVersion - every common model is a versioned entity and contains a version related to their data - a dataVersion.
- realityId - this field indicates what is the reality of the entity.
- deleted - this field indicates whether the entity is "soft deleted".
Let's take a look at a simple example :
@Entity()
export class SimpleEntity extends CommonModel {
...
}
So now SimpleEntity
also includes all of the above properties.
This class extends the typeorm original EntityManager
logic and adds relevant filters and actions such as reality filters,
data version filters and also supports the soft delete mechanism.
You can access this CRUD methods in 2 ways :
- through the
PolarisEntityManager
class. - through typeorm repositories.
Through this config you should set whether you want soft delete mechanism in your repository.
The default value of allowSoftDelete
is true, you can set it to false by sending allowSoftDelete
as false.