move TypeORM library file and tests to experimental

add inline tests :)
Fix TypeORM fuzzy method according to Review
This commit is contained in:
amammad
2023-11-21 19:55:01 +01:00
parent 999ec7053e
commit 0328a2986d
9 changed files with 249 additions and 265 deletions

View File

@@ -1,40 +0,0 @@
| test.ts:19:20:19:50 | "user.f ... rstName |
| test.ts:20:23:20:51 | "user.l ... astName |
| test.ts:80:30:80:37 | 'id > 5' |
| test.ts:86:31:86:38 | 'id > 5' |
| test.ts:95:29:95:44 | "LastNameToFind" |
| test.ts:109:29:109:44 | "LastNameToFind" |
| test.ts:113:13:113:37 | ["first ... tName"] |
| test.ts:114:13:114:26 | ["externalId"] |
| test.ts:120:33:120:43 | "firstname" |
| test.ts:121:16:121:23 | 'id > 5' |
| test.ts:127:16:127:23 | 'id > 5' |
| test.ts:132:29:132:69 | 'SELECT ... id > 5' |
| test.ts:136:17:136:25 | "name,id" |
| test.ts:137:16:137:23 | "id > 5" |
| test.ts:141:47:141:54 | 'id > 5' |
| test.ts:147:66:147:73 | 'id > 5' |
| test.ts:154:16:162:9 | (qb) => ... } |
| test.ts:157:25:157:33 | "name,id" |
| test.ts:159:24:159:31 | 'id > 5' |
| test.ts:168:92:168:108 | "User2.id =:kind" |
| test.ts:173:17:173:23 | "User2" |
| test.ts:175:16:175:23 | 'id > 5' |
| test.ts:180:51:180:78 | "User2. ... id > 5" |
| test.ts:183:52:183:59 | 'id > 5' |
| test.ts:185:53:185:62 | "User2.id" |
| test.ts:185:72:185:79 | 'id > 5' |
| test.ts:189:51:189:58 | 'id > 5' |
| test.ts:193:13:195:14 | new Bra ... }) |
| test.ts:194:26:194:33 | 'id > 5' |
| test.ts:194:44:194:51 | 'id > 5' |
| test.ts:197:18:197:23 | "name" |
| test.ts:197:34:197:41 | 'id > 5' |
| test.ts:202:25:202:32 | 'id > 5' |
| test.ts:208:16:208:23 | 'id > 5' |
| test.ts:210:13:212:14 | new Bra ... }) |
| test.ts:211:26:211:33 | 'id > 5' |
| test.ts:211:44:211:51 | 'id > 5' |
| test.ts:214:13:216:14 | new Not ... }) |
| test.ts:215:26:215:33 | 'id > 5' |
| test.ts:215:44:215:51 | 'id > 5' |

View File

@@ -1,3 +0,0 @@
import javascript
select any(SQL::SqlString s)

View File

@@ -1,218 +0,0 @@
import {
BaseEntity, Brackets, DataSource, JoinColumn, NotBrackets
, OneToOne, Entity, PrimaryGeneratedColumn, Column, SelectQueryBuilder, InsertQueryBuilder
} from "typeorm";
@Entity()
export class UserActiveRecord extends BaseEntity {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Column()
lastName: string
@Column()
age: number
static findByName(firstName: string, lastName: string) {
return this.createQueryBuilder("user")
.where("user.firstName = " + firstName)
.andWhere("user.lastName = " + lastName)
.getMany()
}
}
@Entity()
export class Profile {
@PrimaryGeneratedColumn()
id: number
@Column()
gender: string
@Column()
photo: string
}
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number
@Column()
name: string
@OneToOne(() => Profile)
@JoinColumn()
profile: Profile
}
@Entity()
export class User2 {
@PrimaryGeneratedColumn()
id: number
@Column()
firstName: string
@Column()
lastName: string
@Column()
age: number
}
export const AppDataSource = new DataSource({
type: "sqlite",
database: "database.sqlite",
synchronize: true,
logging: false,
entities: [User, User2, Profile, UserActiveRecord],
migrations: [],
subscribers: [],
})
function makePaginationQuery<T>(q: SelectQueryBuilder<T>): SelectQueryBuilder<T> {
return q;
}
AppDataSource.initialize().then(async () => {
// Active record
await UserActiveRecord.findByName("FirstNameToFind", "LastNameToFind")
// data mapper
const selectQueryBuilder = makePaginationQuery<User>(AppDataSource
.createQueryBuilder(User, "User").select());
selectQueryBuilder.where('id > 5').getMany().then(result => {
console.log(result)
});
const selectQueryBuilder2 = makePaginationQuery<User>(AppDataSource
.createQueryBuilder(User, "User"));
selectQueryBuilder2.where('id > 5').getMany().then(result => {
console.log(result)
});
const insertQueryBuilder: InsertQueryBuilder<User2> = AppDataSource
.createQueryBuilder(User2, "User2").insert();
insertQueryBuilder.into(User2)
.values({
firstName: "Timber",
lastName: () => "LastNameToFind",
age: 33,
}).execute().then(result => {
console.log(result)
})
AppDataSource
.createQueryBuilder(User2, "User")
.insert()
.into(User2)
.values({
firstName: "Timber",
lastName: () => "LastNameToFind",
age: 33,
})
.orUpdate(
["firstName", "lastName"],
["externalId"],
)
.getQueryAndParameters()
await AppDataSource.getRepository(User2).createQueryBuilder("user2")
.update(User2)
.set({ firstName: () => "firstname", lastName: "Saw2", age: 12 })
.where('id > 5')
.execute()
await AppDataSource.getRepository(User2).createQueryBuilder('user2')
.delete()
.from(User2)
.where('id > 5')
.execute()
const queryRunner = AppDataSource.createQueryRunner()
await queryRunner.query('SELECT name,id FROM table1 WHERE id > 5')
await queryRunner.manager
.createQueryBuilder(User2, "User")
.select("name,id")
.where("id > 5").execute()
await AppDataSource
.createQueryBuilder(User, "User")
.innerJoin("User.profile", "profile", 'id > 5', {
id: 2,
}).getMany().then(res => console.log(res))
await AppDataSource
.createQueryBuilder(User, "User")
.leftJoinAndMapOne("User.profile", "profile", "profile", 'id > 5', {
id: 2,
}).getMany().then(res => console.log(res))
await AppDataSource
.createQueryBuilder(User2, "User2")
.where((qb) => {
const subQuery = qb
.subQuery()
.select("name,id")
.from(User2, "user2")
.where('id > 5')
.getQuery()
return "User2.id IN " + subQuery
})
.setParameter("registered", true)
.getMany()
// Using repository
let users = await AppDataSource.getRepository(User2).createQueryBuilder("User2").where("User2.id =:kind", { kind: 1 }).getMany()
// Using DataSource
users = await AppDataSource
.createQueryBuilder()
.select("User2")
.from(User2, "User2")
.where('id > 5', { id: 1 })
.getMany()
// Using entity manager
await AppDataSource.manager
.createQueryBuilder(User2, "User2").where("User2.id =:kind and id > 5", { kind: '1' }).getMany()
await AppDataSource
.createQueryBuilder(User2, "User2")
.leftJoinAndSelect("user.photos", "photo", 'id > 5').getMany()
await AppDataSource
.createQueryBuilder(User2, "User2").groupBy("User2.id").having('id > 5').getMany()
// orderBy
// it is a little bit restrictive, e.g. sqlite don't support it at all
await AppDataSource
.createQueryBuilder(User2, "User2").where('id > 5', {
firstName: "Timber",
})
.where(
new Brackets((qb) => {
qb.where('id > 5').orWhere('id > 5');
})
)
.orderBy("name").orWhere('id > 5').getMany()
// relation
AppDataSource.createQueryBuilder().relation(User, "name")
.of(User)
.select().where('id > 5').getMany().then(results => {
console.log(results)
})
// Brackets
await AppDataSource.createQueryBuilder(User2, "User2")
.where('id > 5')
.andWhere(
new Brackets((qb) => {
qb.where('id > 5').orWhere('id > 5');
})
).andWhere(
new NotBrackets((qb) => {
qb.where('id > 5').orWhere('id > 5')
}),
).getMany()
}).catch(error => console.log(error))

View File

@@ -1,15 +0,0 @@
{
"compilerOptions": {
"lib": [
"es5",
"es6"
],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}
}