Skip to content

Commit

Permalink
Add type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Feb 28, 2024
1 parent 778efb1 commit fb970a5
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 1,194 deletions.
11 changes: 0 additions & 11 deletions .eslintrc.js

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierrc.js

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Gabriel Massadas
Copyright (c) 2024 Gabriel Massadas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,28 @@ export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const qb = new D1QB(env.DB)

const fetched = await qb
.fetchOne({
type Employee = {
name: string
role: string
level: number
}

const employeeList = await qb
.fetchOne<Employee>({
tableName: 'employees',
fields: 'count(*) as count',
fields: '*',
where: {
conditions: 'active = ?1',
params: [true],
},
})
.execute()

// You get IDE type hints on each employee data, like:
// employeeList.results[0].name

return Response.json({
activeEmployees: fetched.results?.count || 0,
activeEmployees: employeeList.results?.length || 0,
})
},
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'./config/fileTransformer.js',
'./config/fileTransformer.cjs',
},
globals: {
'ts-jest': {
Expand Down
Loading

0 comments on commit fb970a5

Please sign in to comment.