Comments (2)
Also, when the API doesn't receive a username the code crashes.
Error:
"MSG: D1_ERROR, Stack:Error: D1_ERROR\n at D1Database._send (d1-beta-facade.entry.js:2113:13)\n at async D1PreparedStatement.all (d1-beta-facade.entry.js:2151:7)\n at async user_search (d1-beta-facade.entry.js:1962:19)\n at async d1-beta-facade.entry.js:2017:19\n at async d1-beta-facade.entry.js:1435:7\n at async d1-beta-facade.entry.js:1375:50"
Here is my code for review:
import { D1QB, OrderTypes } from 'workers-qb'
export async function user_search(c) {
// page integer Which page of results to return (! zero-based !)
// per_page integer How many results to return per page
// order string Attribute/field name to order the responses by
// direction string Either or ASC or DESC
const { page, per_page, order_by, direction, username } = await c.req.json()
// Validate input
var limit, offset;
if (isNumeric(per_page)) {
limit = per_page;
}
if (isNumeric(page)) {
offset = per_page * page;
}
const conditions = []
if (username) {
conditions.push('Username = ?1')
}
const qb = new D1QB(c.env.DB)
var fields = ['Username, Active, EmailVerified, RealName, Perms, Created_on, Modified_on, Modified_by']
const fetched = await qb.fetchAll({
tableName: 'Users',
fields: fields,
where: {
conditions: conditions,
params: [username],
},
//orderBy: { Username: OrderTypes.ASC },
limit: limit,
offset: offset
})
return fetched.results;
}
function checkIfEmpty(str) {
if (typeof str === 'string' || str instanceof String) {
if (!str?.trim() || str.trim().length === 0) {
return true;
} else {
return false;
}
}
return false;
}
function isNumeric(str) {
if (typeof str == "number") { return true; }
if (typeof str != "string") return false // we only process strings!
return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
}
from workers-qb.
Hey @VR-Architect that api crash also seams to be on Cloudflare side, if that still happens maybe you should report that on their Discord Server
from workers-qb.
Related Issues (20)
- Migrations support? HOT 2
- Run prettier on project and commit HOT 1
- Adding support for UPSERT or ON CONFLICT HOT 1
- JOIN support HOT 6
- Syntax error on UPDATE HOT 3
- Order By's DESC/ASC not working HOT 1
- Bulk insert/update we need it HOT 8
- CURRENT_TIMESTAMP is being stored as string rather timestamp HOT 4
- LIKE function not working
- db.batch feature HOT 3
- UPSERT [new feature] HOT 2
- Numbered parameters don't work in miniflare HOT 1
- 0.1.8 HOT 3
- type definitions missing from v1.0.0 HOT 1
- sorry. please delete this issue
- Thanks and quick question about TIMESTAMP HOT 2
- How can I mark an insert as only returning one row?
- alias for main table? HOT 2
- Not null conditions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workers-qb.