Created
June 6, 2020 08:20
-
-
Save bangbang93/23e4cb4ad0aec27631496e28d4fa1ba7 to your computer and use it in GitHub Desktop.
typeorm stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Column, CreateDateColumn, Entity, PrimaryGeneratedColumn} from 'typeorm' | |
@Entity() | |
export class Test { | |
@PrimaryGeneratedColumn() id: number | |
@Column() category: string | |
@CreateDateColumn() createdAt: Date | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {createConnection, getRepository} from 'typeorm' | |
import {Test} from './entity' | |
async function main() { | |
await createConnection({ | |
type: 'mysql', | |
url: 'mysql://root@localhost/temp', | |
entities: [Test], | |
synchronize: true, | |
logging: true, | |
}) | |
const repository = getRepository(Test) | |
const query = repository.createQueryBuilder('t') | |
.select('t.category') | |
.groupBy('t.category') | |
console.log('getMany', await query.getMany()) | |
console.log('getRawMany', await query.getRawMany()) | |
const stream = await query.stream() | |
stream.on('result', (e) => console.log('result', e)) | |
stream.on('end', (e) => console.log('end')) | |
for await(const row of stream) { | |
console.log('stream', row) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment