g4brym / workers-qb Goto Github PK
View Code? Open in Web Editor NEWZero dependencies Query Builder for Cloudflare Workers
Home Page: https://workers-qb.massadas.com
License: MIT License
Zero dependencies Query Builder for Cloudflare Workers
Home Page: https://workers-qb.massadas.com
License: MIT License
Any plans to support ON CONFLICT
clauses to insert
or abstract it behind an upsert
command?
Thanks for the amazing library. Much easier to use than any of the popular ORMs. Anyway, sorry for the noob question, but I see that when updating or inserting, you can use something like this: created_at: new Raw("CURRENT_TIMESTAMP")
What is the underlying schema for a created_at or updated_at to use CURRENT_TIMESTAP? I was previously using something like this in D1: created_at INTEGER DEFAULT (cast(strftime('%s', 'now') as INTEGER)),
With the Raw, though, I'm not clear how it should be stored, as I don't see Timestamp as a data type in SQLite. Or is the CURRENT_TIMESTAMP only for postgres?
Thanks.
Thank you for this package
Do you plan to add also migrations support?
I'm not familiar with releasing node packages, but it looks like the type definitions are missing from the v1.0.0 release. The v0.1.12 release had the type declaration files in the top level of the dist
directory. In the v1.0.0 release, it looks like there is a src
directory that was absent in the v0.1.12 release, and the type declaration files are there instead of in the top level of the dist
directory.
const tableData = {
id,
name,
user_id: user.id,
created_at: "CURRENT_TIMESTAMP",
updated_at: "CURRENT_TIMESTAMP",
};
This is being stored as string for created_at and updated_at.
await qb.fetchAll({
tableName: 'users',
fields: ['name', 'email'],
where: {
conditions: ["name LIKE '%?1%'"],
params: ['John'],
},
orderBy: {
name: 'DESC',
},
});
I have a basic "update multiple fields" query that throws a syntax error. It's generating this query:
UPDATE pages SET (content = ?2) WHERE id = ?1
–which doesn't appear to be a valid statement. I'm not super familiar with SQL anymore, but it seems like removing the parentheses would correct the syntax.
Additionally, looking through the code, I noticed this query:
UPDATE pages SET (content = ?2, category = ?3) WHERE id = ?1
–was being called with these parameters being binded:
[ 'banana1', 'news', 'test' ]
In this case, the id is test
, the content is banana1
and the category is news
. It seems like ?1
and ?2
are being swapped. Is this intentional?
Hi, 0.1.8 is asking me to turn on node_compat
when deploying a worker with wrangler even though i only use the D1 bindings.
Bulk insert/update we need it please update the package
Is there anyway to perform JOIN query? If there is, how can I do it?
Try to implement db.batch for all workers-qb operation.
await db.batch([
db.prepare("UPDATE users SET name = ?1 WHERE id = ?2").bind( "John", 17 ),
db.prepare("UPDATE users SET age = ?1 WHERE id = ?2").bind( 35, 19 ),
]);
Hi,
I tried the advanced where clause and I am getting an error on the conditions.push('department = ?1') line. The error says "TS2345 (TS) Argument of type 'string' is not assignable to parameter of type 'never'."
Reference:
https://workers-qb.massadas.com/advanced-queries/where/
UPDATE: The command actually works fine if I ignore the error message.
Putting together a PR but getting a lot of syntax noise. Can you check your prettier settings then run npx prettier --write .
and once you're happy with the result, commit it to master
and I'll PR off that?
UPSERT is a very useful feature for developers please try to add this feature in workers-qb package.
FYI, I have not been able to get the DESC/ASC command to work in plan Cloudflare. I added this library and noticed the issue. The result set is the same order for both DESC and ASC.
I tried it with OrderTypes and the 'ASC' string. I believe there may be a bug in the Cloudflare side though?
As numbered parameters don't work in miniflare, workers-qb is unable to be used with wrangler dev when run locally. More details on the issue here - https://discord.com/channels/595317990191398933/1080287346794168381
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.