iwinston / typeorm-plus Goto Github PK
View Code? Open in Web Editor NEWTypeORM+ adds functionality to TypeORM intending to make the Repository and QueryBuilder more powerful.
License: MIT License
TypeORM+ adds functionality to TypeORM intending to make the Repository and QueryBuilder more powerful.
License: MIT License
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Hi. I tried to get a deleted entity from the database. But it seems that findOne
with scope doesn't work.
const deleteId = product.id;
// some codes for deleting the product...
// ...
const deletedProduct = await getRepository(Product).findOne(deleteId, {scope: 'deleted'});
expect(deletedProduct).toBeNull(); // because `deletedProduct` is undefined.
The query shows that the scope option is not properly applied to the query builder. (AND Product.deletedAt IS NULL
)
SELECT DISTINCT `distinctAlias`.`Product_id` as "ids_Product_id" FROM (SELECT `Product`.`id` AS `Product_id`, `Product`.`name` AS `Product_name`, `Product`.`description` AS `Product_description`, `Product`.`price` AS `Product_price`, `Product`.`detailLink` AS `Product_detailLink`, `Product`.`brandName` AS `Product_brandName`, `Product`.`imageLinks` AS `Product_imageLinks`, `Product`.`createdAt` AS `Product_createdAt`, `Product`.`updatedAt` AS `Product_updatedAt`, `Product`.`deletedAt` AS `Product_deletedAt`, `Product_brand`.`name` AS `Product_brand_name`, `Product_brand`.`url` AS `Product_brand_url`, `Product_brand`.`createdAt` AS `Product_brand_createdAt`, `Product_hashtags`.`name` AS `Product_hashtags_name`, `Product_hashtags`.`createdAt` AS `Product_hashtags_createdAt` FROM `product` `Product` LEFT JOIN `brand` `Product_brand` ON `Product_brand`.`name`=`Product`.`brandName` LEFT JOIN `product_hashtags_hashtag` `Product_Product_hashtags` ON `Product_Product_hashtags`.`productId`=`Product`.`id` LEFT JOIN `hashtag` `Product_hashtags` ON `Product_hashtags`.`name`=`Product_Product_hashtags`.`hashtagName` WHERE `Product`.`id` IN ("1993bf98-e902-41cc-989c-d871ca0adbf4") AND `Product`.`deletedAt` IS NULL) `distinctAlias` ORDER BY `Product_id` ASC LIMIT 1
Here is my entity class
@Entity()
export class Product extends BaseEntity {
public static scope = {
deleted: {
deletedAt: Not(IsNull()),
},
};
//some codes...
}
I don't know why the find
works as expected but findOne
doesn't.
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
hi I was just taking a look at the diff here: iWinston:00d46e...master
curious why you deleted the package.lock file?
also just to verify my understanding - should softRemove
work with cascades?
Issue type:
[x] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I'm running this code and getting the reponse with deleted posts:
Find
const userRepository = await this.userRepository.findOne({
where: {
id: id,
},
relations: ['posts'],
});
Response
{
"id": 4,
"name": "Michael Jordan",
"createdAt": "2020-09-26T23:07:13.000Z",
"updatedAt": "2020-09-26T23:07:13.000Z",
"deletedAt": null,
"posts": [
{
"id": 5,
"name": "Post One",
"createdAt": "2020-09-26T23:07:45.000Z",
"updatedAt": "2020-09-26T23:08:27.000Z",
"deletedAt": "2020-09-26T23:08:27.000Z"
},
{
"id": 6,
"name": "Post Two",
"createdAt": "2020-09-26T23:14:09.000Z",
"updatedAt": "2020-09-26T23:14:20.000Z",
"deletedAt": null,
}
]
}
How can i filter to get only not deleted posts?
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
I'd like to be able to use a decorator similar to @DeleteDateColumn
(e.g. @DeleteColumn
) which provides the same soft delete functionality when querying entities, but implemented with boolean
type instead of Date
.
This would be useful in the case where the typescript code doesn't manage the schema of the database, and the managing system uses booleans to implement soft deletes (e.g. Hibernate ORM in Java).
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I have an issue with a cascade softRemove on relations. This is the entry for a Client table
@Field(_ => [Patient])
@OneToMany(
_ => Patient,
patient => patient.owner,
{ lazy: true, cascade: true },
)
public patients: Lazy<Patient[]>
So when i do softRemove on a client entry it should do softRemove on all patients. This is how I do softRemove on my service:
async removeById(id: string) {
const client = await this.getById(id)
return this.clientRepository.softRemove(client)
}
It soft removed a client correctly however all patients where client is the owner are not soft removed. Could you point where the error is? I have even tried this but it also didn't worked:
@Field(_ => [Patient])
@OneToMany(
_ => Patient,
patient => patient.owner,
{ lazy: true, cascade: true, onDelete: 'CASCADE' },
)
public patients: Lazy<Patient[]>
or even on the Patient table which also didn't worked
@Field(_ => Client)
@ManyToOne(_ => Client, { lazy: true, cascade: true })
public owner: Lazy<Client>
I come from laravel background which has pretty nice ways to handle polymorphism. My use cases are going to be having comments, status, bookmarks that could apply for multiple things.. like you could bookmark a user, comment, or post.
It'd be nice to just have some reusable decorators to get this out of the box. Since soft deletes and query scopes are very familiar to laravel, seems maybe polymorphism could be something this package could add to typeorm and make it closer to eloquent.
Issue type:
[ ] question
[ ] bug report
[x] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Issue type:
[ ] question
[X ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ X] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[X ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Hi Im using softDelete functionality of your library but Im having problem when used with Subscribers, I cannot get the entity model that was updated ??
import { EntitySubscriberInterface, EventSubscriber, InsertEvent, UpdateEvent, RemoveEvent } from 'typeorm';
import { Subscriber } from './subscriber.entity';
@EventSubscriber()
export class RevisionSubscriber {
/**
* Indicates that this subscriber only listen to User events.
*/
listenTo() {
return Subscriber;
}
/**
* Called after User update.
*/
async afterUpdate(event: UpdateEvent<Subscriber>) {
console.log('Eventtttt ');
console.log(event.databaseEntity); // this is undefined
console.log(event.entity)// this is also undefined
}
async beforeUpdate(event) {
console.log('Eventtttt ');
console.log(event.databaseEntity); // this is undefined
console.log(event.entity)// this is also undefined
}
}
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Hey, love the project - been looking for soft deletes in TypeORM for a while!
I noticed that you're not preserving the whitespace rules that TypeORM uses so your diffs are really large as you make your customizations. Given you'll need to continuously pull in the latest from TypeORM , does It make sense to obey their whitespace rules by shutting auto-formatters off so that rebasing will be easier?
Also, are you planning on maintaining this project long-term?
Thanks!
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
The soft delete scope of filtering out entries which have a deletedAt
column set does not get applied to relations - eg:
this.wishlistRepository.findOne({
id: wishlistItemId,
}, {
relations: ['owner']
})
The SQL generated correctly filters based on the deletedAt
column in the wishlist entity but doesn't also get pushed down into the join on the owner
entity
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
I loved this initiative! I had some issues with TypeORM maintainer, as seen at typeorm/typeorm#4686.
I've started a fork seeking to fix some of the troubles I noted there, but it's kind sad to be alone. Now that I have found you, would you mind if I participate here? Let's join forces to grow this project, what do you thing?
I already have a project in production, circa 4k-6k simultaneous access sometimes during a day. I am willing to replace typeorm
by typeorm-plus
there, could be a showcase.
@iWinston congrats
Issue type:
[*] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[*] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[*] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
TypeORM's original query builder requires andWhere
or orWhere
after the first where
call. Otherwise it overrides existing where
condition. The first where
call can differ depending on the request parameters so it's hard to keep track of the where calls (which one is first, which one is second etc...).
Hello
Love the library!
Do you keep up to date with the latest TypeOrm changes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.