wwwouter / typed-knex

A TypeScript wrapper for Knex.js
MIT License
112 stars 13 forks source link

Can I use `forUpdate` in `typed-knex` ? #49

Closed SSShuai1999 closed 2 years ago

SSShuai1999 commented 2 years ago

Issue type:

[ ] Question [ ] Bug report [ ] Feature request [x] Documentation issue

Database system/driver:

[ ] Postgres [ ] MSSQL [x] MySQL [ ] MariaDB [ ] SQLite3 [ ] Oracle [ ] Amazon Redshift

typed-knex version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Knex.js version:

First of all, thank you so much for your work! I love this library!

This issues mainly asks about how the forUpdate function in knex is used in typed-knex!

wwwouter commented 2 years ago

The forUpdate is not supported directly, but you can use it through useKnexQueryBuilder

        const typedKnex = new TypedKnex(knex({ client: "postgresql" }));
        const query = typedKnex.query(UserCategory);
        query.useKnexQueryBuilder((q) => {
            q.forUpdate();
        });
        assert.equal(query.toQuery(), "select * from "userCategories" for update");

Does this solve your problem?

SSShuai1999 commented 2 years ago

Thanks for your answer! I closed it.