Hey! Absolutely love SST! It has made me almost ...
# help
p
Hey! Absolutely love SST! It has made me almost move all my firebase side projects over to AWS šŸ˜± . Currently my team has the opportunity to green field a project... so I picked all new technology because paying me to learn! We started with aws amplify and after grinding for 6 weeks on it we removed it for SST and CDK and man... took like 2 days to replicate everything šŸ˜† . Again... awesome work. We would like to use Aurora with TypeORM and have it "working" but obviously there are limitations with esbuild (also another project that made my jaw drop). I believe there is a discussions for SST to include plugins so we can support emitDecoratorMetadata but I'm worried about gotchas there. So my question is... what are other people using for this layer? Specifically the entity manager layer which helps with consistency of updatedAt / createdAt / validation / migrations / etc. I usually just write my own but... you know bugs šŸ™‚... and documentation šŸ™‚... I find it fun though...
f
Hey @Patrick Young! Just to clarify, by
what are other people using for this layer
You mean what r ppl using for their ORM? Not a Lambda layer right?
b
@Patrick Young I've just started putting together an SST Api Stack that uses RDS MySQL and
Sequelize
. Seems to be working out so far.
p
Yup the ORM layer. (if you are using it).
I will have to check out Sequelize! Thanks!
t
I have things going with Prisma
p
We are going to be a heavy CRUD app so I'm wrapping the SST Api Construct with... crazy! Just started hacking around it but it maps everything to one handler which then looks up the routeKey to know what function to execute. This allows me to have consistent validation of body/params/query/authorization/etc. Here is a some of the hack work:
Copy code
export const userRoutes: RouteController<User> = {
    users: {
        dbType: LambdaDBType.AURORA,
        db: getRepository(User),
        routes: [
            {
                method: "POST",
                route: "/",
                execute: create,
                validateBody: createUserSchema,
                authorization: ["CREATE_USER"]
            },
            {
                method: "GET",
                route: "/{id}",
                execute: findOne,
                validateQuery: findOneUserQuerySchema,
                validateParams: findOneUserParamsSchema
            },
            {
                method: "GET",
                route: "/",
                execute: find,
                validateQuery: findUserQuerySchema
            }
        ]
    }
};

export async function create(event: ApiEvent): Promise<User> {
    const createdUser = event.db.create(event.body);

    return event.db.save(createdUser);
}

export async function find({ db }: ApiEvent): Promise<User[]> {
    const user = await db.find();

    return user;
}

export async function findOne({ db, params }: ApiEvent): Promise<User | undefined> {
    const user = await db.findOne(params.id);

    return user;
}
@thdxr We had a dev spike on Prisma and it looked really cool! We were thinking of having AWS own our souls and at the time weren't sure on support for Aurora. I think it was also in Beta?... but doesn't seem to be now? Might have to relook at it though!
a
Iā€™ve used Sequalize before, but TypeORM is way better.
Sequalize has lots of issues when creating complex joins and such.
Also TypeORM works very well with Typescript.
t
Prisma works fine with anything that supports a postgres or mysql connection
So fine with Aurora
It doesn't support data api yet on serverless aurora so a bit awkward in a serverless environment (have to maintain connections) but not terrible
r
There's a v2 of aurora in preview that has much faster spin up times and various other things but isn't yet recommended for production until it's GA. V1 works well though and the connection management issue can be mitigated using serverless-mysql (if you use the Mysql flavour) or RDS Proxy if you don't mind some extra cost