Shane
Shane
Explore posts from servers
KPCKevin Powell - Community
Created by Shane on 5/1/2024 in #back-end
Confused by Kysely
I'm using kysely for a project and I'm using it to create tables, however now that I create the tables with the columns and behaviors I want, I need to essentially do the same by writing the typescript type, which seems bad. Am I missing something or is that really how I'm expected to do this? for example here is a users table
const createUserTable = async () => {
await db.schema
.createTable("users")
.addColumn("id", "integer", (cb) =>
cb.primaryKey().autoIncrement().notNull()
)
.addColumn("email", "varchar(255)", (cb) => cb.notNull().unique())
.addColumn("password", "varchar(255)", (cb) => cb.notNull())
.addColumn("is_admin", "boolean", (cb) => cb.notNull().defaultTo(false))
.addColumn("first_name", "varchar(255)", (cb) => cb.notNull())
.addColumn("last_name", "varchar(255)")
.addColumn("created_at", "timestamp", (cb) =>
cb.notNull().defaultTo(sql`current_timestamp`)
)
.addColumn("last_login", "timestamp")
.execute();
};
const createUserTable = async () => {
await db.schema
.createTable("users")
.addColumn("id", "integer", (cb) =>
cb.primaryKey().autoIncrement().notNull()
)
.addColumn("email", "varchar(255)", (cb) => cb.notNull().unique())
.addColumn("password", "varchar(255)", (cb) => cb.notNull())
.addColumn("is_admin", "boolean", (cb) => cb.notNull().defaultTo(false))
.addColumn("first_name", "varchar(255)", (cb) => cb.notNull())
.addColumn("last_name", "varchar(255)")
.addColumn("created_at", "timestamp", (cb) =>
cb.notNull().defaultTo(sql`current_timestamp`)
)
.addColumn("last_login", "timestamp")
.execute();
};
Now if I want this to have typescript types I have to write this as well
export interface UsersTable {

id: Generated<number>;
email: string;
password: string;

is_admin: Generated<0 | 1>;
first_name: string;
last_name: string | null;

created_at: ColumnType<Date, string | undefined, never>;
last_login: Date | null;
}

export type User = Selectable<UsersTable>;
export type NewUser = Insertable<UsersTable>;
export type UserUpdate = Updateable<UsersTable>;
export interface UsersTable {

id: Generated<number>;
email: string;
password: string;

is_admin: Generated<0 | 1>;
first_name: string;
last_name: string | null;

created_at: ColumnType<Date, string | undefined, never>;
last_login: Date | null;
}

export type User = Selectable<UsersTable>;
export type NewUser = Insertable<UsersTable>;
export type UserUpdate = Updateable<UsersTable>;
I would think that the library should be able to auto generate this type from all the information I give it when I create the damn table
8 replies
KPCKevin Powell - Community
Created by Shane on 4/20/2024 in #back-end
next auth help
does anyone have experience with next auth? I'm finding the documentation to be sub par. Currently I'm struggling to figure out how to handle signin errors using the credentials provider.
3 replies
KPCKevin Powell - Community
Created by Shane on 4/8/2024 in #ui-ux
make this look less bad
No description
15 replies
KPCKevin Powell - Community
Created by Shane on 4/3/2024 in #ui-ux
is this button too much
https://svgzip.com/ would love some general design feedback. I feel like I maybe went a bit overboard with the button CSS animation, but lmk (the background animation is only visiblein dark mode, oop) it looks way better in dark mode so open to suggestions for making the lightmode pretty
13 replies
KPCKevin Powell - Community
Created by Shane on 3/27/2024 in #back-end
creating a historical database for graph generation
Anyone have opinions / thoughts / experience on the best way to store database history? Like if I was storing the values of a stock ticker and wanted to generate a graph of stock price over time (not my actual use case but similar idea). Seems like there are a lot of wrong ways to do it. I'll be accessing the DB with an expressJS server and I haven't choosen a database stack yet
116 replies
CDCloudflare Developers
Created by Shane on 1/3/2024 in #workers-help
typescript durable objects transaction api
Is there an example of how to type durable objects in the storage api?
state: DurableObjectState;
webSockets: Set<WebSocket>;
storage: DurableObjectStorage;
constructor(state: DurableObjectState, env: Env) {
this.state = state;
this.storage = state.storage;
this.webSockets = new Set();
}
state: DurableObjectState;
webSockets: Set<WebSocket>;
storage: DurableObjectStorage;
constructor(state: DurableObjectState, env: Env) {
this.state = state;
this.storage = state.storage;
this.webSockets = new Set();
}
I guess I'd want to define the type of stuff accessed through this.storage.get()/set()
2 replies
CDCloudflare Developers
Created by Shane on 10/21/2023 in #workers-help
worker functions locally, but not when deployed
In production this code fails to retrieve data like 80% of the time. I added some debugging code to retry the request in the worker and it sometimes will fail the first x requests and eventually works and sometimes it fails all the requests. When running locally it works 100% of the time. Is there a way I can run cloudflare workers on my own servers (open to suggestions for cloud providers) , or a way to fix my code to make this work 100% of the time? Here is a link you can open to test and the source code is attached https://banner.mines.rocks/?season=fall&year=2021&courseNumber=250&subject=CSCI
36 replies