Fix bugs
Use Not(IsNull())
This commit is contained in:
parent
5a3ea38bbf
commit
e7dd5e155d
@ -128,6 +128,20 @@ query.andWhere(new Brackets(qb => {
|
|||||||
}));
|
}));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Not `null` in TypeORM
|
||||||
|
```ts
|
||||||
|
const foo = await Foos.findOne({
|
||||||
|
bar: Not(null)
|
||||||
|
});
|
||||||
|
```
|
||||||
|
のようなクエリ(`bar`が`null`ではない)は期待通りに動作しない。
|
||||||
|
次のようにします:
|
||||||
|
```ts
|
||||||
|
const foo = await Foos.findOne({
|
||||||
|
bar: Not(IsNull())
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### `null` in SQL
|
### `null` in SQL
|
||||||
SQLを発行する際、パラメータが`null`になる可能性のある場合はSQL文を出し分けなければならない
|
SQLを発行する際、パラメータが`null`になる可能性のある場合はSQL文を出し分けなければならない
|
||||||
例えば
|
例えば
|
||||||
|
@ -4,7 +4,7 @@ import define from '../../define';
|
|||||||
import { maximum } from '../../../../prelude/array';
|
import { maximum } from '../../../../prelude/array';
|
||||||
import { ApiError } from '../../error';
|
import { ApiError } from '../../error';
|
||||||
import { getUser } from '../../common/getters';
|
import { getUser } from '../../common/getters';
|
||||||
import { Not, In } from 'typeorm';
|
import { Not, In, IsNull } from 'typeorm';
|
||||||
import { Notes, Users } from '../../../../models';
|
import { Notes, Users } from '../../../../models';
|
||||||
import { types, bool } from '../../../../misc/schema';
|
import { types, bool } from '../../../../misc/schema';
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ export default define(meta, async (ps, me) => {
|
|||||||
const recentNotes = await Notes.find({
|
const recentNotes = await Notes.find({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
replyId: Not(null)
|
replyId: Not(IsNull())
|
||||||
},
|
},
|
||||||
order: {
|
order: {
|
||||||
id: -1
|
id: -1
|
||||||
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
|||||||
import Chart, { Obj, DeepPartial } from '../../core';
|
import Chart, { Obj, DeepPartial } from '../../core';
|
||||||
import { SchemaType } from '../../../../misc/schema';
|
import { SchemaType } from '../../../../misc/schema';
|
||||||
import { DriveFiles } from '../../../../models';
|
import { DriveFiles } from '../../../../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
import { DriveFile } from '../../../../models/entities/drive-file';
|
import { DriveFile } from '../../../../models/entities/drive-file';
|
||||||
import { name, schema } from '../schemas/drive';
|
import { name, schema } from '../schemas/drive';
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ export default class DriveChart extends Chart<DriveLog> {
|
|||||||
protected async fetchActual(): Promise<DeepPartial<DriveLog>> {
|
protected async fetchActual(): Promise<DeepPartial<DriveLog>> {
|
||||||
const [localCount, remoteCount, localSize, remoteSize] = await Promise.all([
|
const [localCount, remoteCount, localSize, remoteSize] = await Promise.all([
|
||||||
DriveFiles.count({ userHost: null }),
|
DriveFiles.count({ userHost: null }),
|
||||||
DriveFiles.count({ userHost: Not(null) }),
|
DriveFiles.count({ userHost: Not(IsNull()) }),
|
||||||
DriveFiles.clacDriveUsageOfLocal(),
|
DriveFiles.clacDriveUsageOfLocal(),
|
||||||
DriveFiles.clacDriveUsageOfRemote()
|
DriveFiles.clacDriveUsageOfRemote()
|
||||||
]);
|
]);
|
||||||
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
|||||||
import Chart, { Obj, DeepPartial } from '../../core';
|
import Chart, { Obj, DeepPartial } from '../../core';
|
||||||
import { SchemaType } from '../../../../misc/schema';
|
import { SchemaType } from '../../../../misc/schema';
|
||||||
import { Notes } from '../../../../models';
|
import { Notes } from '../../../../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
import { Note } from '../../../../models/entities/note';
|
import { Note } from '../../../../models/entities/note';
|
||||||
import { name, schema } from '../schemas/notes';
|
import { name, schema } from '../schemas/notes';
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export default class NotesChart extends Chart<NotesLog> {
|
|||||||
protected async fetchActual(): Promise<DeepPartial<NotesLog>> {
|
protected async fetchActual(): Promise<DeepPartial<NotesLog>> {
|
||||||
const [localCount, remoteCount] = await Promise.all([
|
const [localCount, remoteCount] = await Promise.all([
|
||||||
Notes.count({ userHost: null }),
|
Notes.count({ userHost: null }),
|
||||||
Notes.count({ userHost: Not(null) })
|
Notes.count({ userHost: Not(IsNull()) })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
|||||||
import Chart, { Obj, DeepPartial } from '../../core';
|
import Chart, { Obj, DeepPartial } from '../../core';
|
||||||
import { SchemaType } from '../../../../misc/schema';
|
import { SchemaType } from '../../../../misc/schema';
|
||||||
import { Followings, Users } from '../../../../models';
|
import { Followings, Users } from '../../../../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
import { User } from '../../../../models/entities/user';
|
import { User } from '../../../../models/entities/user';
|
||||||
import { name, schema } from '../schemas/per-user-following';
|
import { name, schema } from '../schemas/per-user-following';
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ export default class PerUserFollowingChart extends Chart<PerUserFollowingLog> {
|
|||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
Followings.count({ followerId: group, followeeHost: null }),
|
Followings.count({ followerId: group, followeeHost: null }),
|
||||||
Followings.count({ followeeId: group, followerHost: null }),
|
Followings.count({ followeeId: group, followerHost: null }),
|
||||||
Followings.count({ followerId: group, followeeHost: Not(null) }),
|
Followings.count({ followerId: group, followeeHost: Not(IsNull()) }),
|
||||||
Followings.count({ followeeId: group, followerHost: Not(null) })
|
Followings.count({ followeeId: group, followerHost: Not(IsNull()) })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -2,7 +2,7 @@ import autobind from 'autobind-decorator';
|
|||||||
import Chart, { Obj, DeepPartial } from '../../core';
|
import Chart, { Obj, DeepPartial } from '../../core';
|
||||||
import { SchemaType } from '../../../../misc/schema';
|
import { SchemaType } from '../../../../misc/schema';
|
||||||
import { Users } from '../../../../models';
|
import { Users } from '../../../../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
import { User } from '../../../../models/entities/user';
|
import { User } from '../../../../models/entities/user';
|
||||||
import { name, schema } from '../schemas/users';
|
import { name, schema } from '../schemas/users';
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ export default class UsersChart extends Chart<UsersLog> {
|
|||||||
protected async fetchActual(): Promise<DeepPartial<UsersLog>> {
|
protected async fetchActual(): Promise<DeepPartial<UsersLog>> {
|
||||||
const [localCount, remoteCount] = await Promise.all([
|
const [localCount, remoteCount] = await Promise.all([
|
||||||
Users.count({ host: null }),
|
Users.count({ host: null }),
|
||||||
Users.count({ host: Not(null) })
|
Users.count({ host: Not(IsNull()) })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import * as promiseLimit from 'promise-limit';
|
import * as promiseLimit from 'promise-limit';
|
||||||
import del from '../services/drive/delete-file';
|
import del from '../services/drive/delete-file';
|
||||||
import { DriveFiles } from '../models';
|
import { DriveFiles } from '../models';
|
||||||
import { Not } from 'typeorm';
|
import { Not, IsNull } from 'typeorm';
|
||||||
import { DriveFile } from '../models/entities/drive-file';
|
import { DriveFile } from '../models/entities/drive-file';
|
||||||
import { ensure } from '../prelude/ensure';
|
import { ensure } from '../prelude/ensure';
|
||||||
|
|
||||||
const limit = promiseLimit(16);
|
const limit = promiseLimit(16);
|
||||||
|
|
||||||
DriveFiles.find({
|
DriveFiles.find({
|
||||||
userHost: Not(null)
|
userHost: Not(IsNull())
|
||||||
}).then(async files => {
|
}).then(async files => {
|
||||||
console.log(`there is ${files.length} files`);
|
console.log(`there is ${files.length} files`);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user