Is there any existing guides/guidance for working ...
# help
s
Is there any existing guides/guidance for working with
typeORM
for serverless-stack, or is the consensus to use
kysely
instead? [Postgres Aurora Serverless] (I'm converting an existing serverless project to serverless-stack that currently uses typeORM, so I'm weighing up the challenges of converting vs wiring up typeORM)
f
Yeah pretty much. What I picked up from @thdxr and the community is that: • ur lambda zip file will be smaller when using
kysely
, so shorter cold start time • Kysely is complete typesafe which is handy if u r using TS
That said, @Scott r u using Data Api with TypeORM?
s
Yes, previously I was using typeorm-aurora-data-api-driver, but good to know, I'll dive a bit dpeer into Kysely. I think my 2 biggest question marks for it from a preliminary understanding are: • Can Kysely handle subscriptions (trigger something when a field is inserted/updated) • How well it handles custom SQL, (some advanced search conditions that require SQL extensions, which generally cannot be done from ORMs)
@Frank From my work today it seems like converting to Kysely is a pretty big job (45 existing entities + 100ish queries to alter), With that in mind I decided to investigate typeORM. Currently getting blocked by a requests that get no responses. i.e. • I have a Kysely route, works fine • I have a typeOrm route, requests are made, backend is receiving them, but the handler is never hit/errors out Is there somewhere I should put a breakpoint that will always be hit to allow me to step through and find out where it's getting stuck?
f
I will let @thdxr chime in. He’s more familiar with Kysely.
Lemme also tag @Sami Koskimäki, he’s the father of Kysely 😁
s
Sounds good, if we're talking about Kysely, I think the main things I would need to know if I was to convert to it, is if it can cover all features that I'm currently using from typeORM, which includes: • Table Subscriber events • Materialized Views <-- currently using postgres for searching via similarity/ts_vectors, eventually would spend the time and resources to use an elastic-search/no-sql db. • Versioning Tracking <-- prevent two people altering same row • Row Migration <-- populating key tables with data • Soft Delete
Update on using TypeORM, I've managed to get a proper connection working, and get Migrations in, the getting stuck appears to relate to including any of my entities. E.g. If I include any entites I get the following: (top including an entity, bottom no entities)
For context my data-source.ts looks as follows: I'm going to try and create a simpler entity to see if that has an effect, as the User entity branches out to many other entities, so it may be one entity bringing down the whole ship
Copy code
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import * as entities from './entities';
import { User } from './entities/entity/User';
import * as subscribers from './entities/subscriptions';
import * as migrations from './entities/migrations';
import 'typeorm-aurora-data-api-driver';

let AppDataSource = new DataSource({
    type: 'postgres',
    host: 'localhost',
    port: 5432,
    username: 'postgres',
    password: 'admin',
    database: 'postgres',
    logging: true,
    // entities: [...Object.values(entities)],
    // subscribers: [...Object.values(subscribers)],
    migrations: [...Object.values(migrations)],
});

if (process.env.SECRET_ARN) {
    AppDataSource = new DataSource({
        type: 'aurora-postgres',
        database: 'medii',
        secretArn: process.env.SECRET_ARN ?? '',
        resourceArn: process.env.CLUSTER_ARN ?? '',
        region: process.env.REGION ?? 'ap-southeast-2',
        logging: true,
        entities: [User],
        // subscribers: [],
        migrations: [...Object.values(migrations)],
    });
}

export default AppDataSource;
Eureka, got typeORM working
k
@Scott is building the actual function taking a lot of time for you ?
I am also using typeorm but it is taking a lot of time for the initial build (first requests)
@thdxr ^ this is very weird is there a way I could log how long it takes to build a function? it feels like building one single function is taking up to 10s 😅
I even added
typeorm
to
nodeModules
ah… it is
@anatine/esbuild-decorators
s
Sorry @Kujtim Hoxha I ran into quite a few blockers and actually have started rebuilding all my functions with Kysely, pretty big job, but I am seeing some size reduction on my lambdas which is nice, as typeORM can carry quite alot of overhead.