asg017 / sqlite-ulid

A SQLite extension for generating and working with ULIDs
Apache License 2.0
123 stars 6 forks source link

Publish types for npm package. #9

Open deadcoder0904 opened 5 months ago

deadcoder0904 commented 5 months ago

I asked ChatGPT for types & it gave this:

declare module "sqlite-ulid" {
  export function getLoadablePath(): string;
}

Can you publish this? I'll use a global.d.ts in the meantime :)

And thanks for the project. Does it add ulid to id automatically?

deadcoder0904 commented 5 months ago

Bdw, I tried starting the application & I got this error:

Error: Loadble extension for sqlite-ulid not found. Was the sqlite-ulid-windows-x64 package installed? Avoid using the --no-optional flag, as the optional dependencies for sqlite-ulid are required.

Do I need to install https://www.npmjs.com/package/sqlite-ulid-windows-x64 too?

Windows instructions unclear.

deadcoder0904 commented 5 months ago

Okay, I think installing sqlite-ulid-windows-x64 solved it for seed command.

But when I run my application, I get this error:

⨯ TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of URL. Received an instance of URL

Idk what to do now?

deadcoder0904 commented 5 months ago

I tried .toString() method too but that didn't work.

Here's my code:

import { drizzle } from 'drizzle-orm/better-sqlite3'
import sqlite from 'better-sqlite3'
import * as sqlite_ulid from 'sqlite-ulid'

const client = sqlite(process.env.DATABASE_PATH)
client.pragma('journal_mode = WAL') // see https://github.com/WiseLibs/better-sqlite3/blob/master/docs/performance.md
client.loadExtension(sqlite_ulid.getLoadablePath())

export const db = drizzle(client)

I'm using it for this project on sqlite branch if you wanna clone & test -> https://github.com/deadcoder0904/next-13-lucia-auth-drizzle-turso-sqlite-magic-link/tree/sqlite

Lmk if there are any solutions? I can't find anything on this online.

deadcoder0904 commented 5 months ago

Alright, I'll use ulidx npm package as an alternative for now with drizzle's $defaultFn like:

import { ulid } from "ulid";

export const users = sqliteTable("users", {
  id: text("id")
    .primaryKey()
    .$defaultFn(() => ulid()),
});

Courtesy of https://www.answeroverflow.com/m/1191758386711253133