Libsql mapHranaError

Using Drizzle with Turso with the following schema and code and receiving a libsql error as shown. @libsql/client@0.4.0-pre.5 drizzle-kit@0.20.6 drizzle-orm@0.29.1 elysia@0.7.29 libsql@0.2.0-pre.4
//schema.ts
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const assignments = sqliteTable('assignments', {
id: text('id').primaryKey(),
name: text('name'),
dateCreated: text('dateCreated'),
}
);
//schema.ts
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';

export const assignments = sqliteTable('assignments', {
id: text('id').primaryKey(),
name: text('name'),
dateCreated: text('dateCreated'),
}
);
// dbUtils.ts
import { drizzle } from 'drizzle-orm/libsql';
import { eq } from 'drizzle-orm';
import { createClient } from '@libsql/client';
import { assignments } from '../db/schema';
import { Assignment } from './types';

// define constants
const client = createClient({
url: process.env.TURSO_URL ,
authToken: process.env.TURSO_AUTH_TOKEN,
});

const db = drizzle(client);

export async function getAssignment(assignmentid:string){
const assignmentList = await db.select().from(assignments).where(eq(assignments.id, assignmentid)).execute();
return assignmentList;
}

// define the function
async function checkAssignmentState(assignmentid:string) {
const assignmentList = await db.select().from(assignments).where(eq(assignments.id, assignmentid)).execute();
if (assignmentList.length === 0) {
const state: string = "null";
return state;
}
return assignmentList;
}

async function writeAssignment(assignment:Assignment) {
const date = new Date().toUTCString(); // notiible bug
await db.insert(assignments).values([{ id: assignment.id, name: assignment.name, dateCreated: date }]).execute();
}

export async function coreDB(assignment:Assignment){
const id = assignment.id
const state = await checkAssignmentState(id);
if (state === "null") {
await writeAssignment(assignment);
}
else {
return state;
}
}

try{
const output = await db.select().from(assignments).execute();
console.log(output)
}
catch(error){
console.log(error);
}
// dbUtils.ts
import { drizzle } from 'drizzle-orm/libsql';
import { eq } from 'drizzle-orm';
import { createClient } from '@libsql/client';
import { assignments } from '../db/schema';
import { Assignment } from './types';

// define constants
const client = createClient({
url: process.env.TURSO_URL ,
authToken: process.env.TURSO_AUTH_TOKEN,
});

const db = drizzle(client);

export async function getAssignment(assignmentid:string){
const assignmentList = await db.select().from(assignments).where(eq(assignments.id, assignmentid)).execute();
return assignmentList;
}

// define the function
async function checkAssignmentState(assignmentid:string) {
const assignmentList = await db.select().from(assignments).where(eq(assignments.id, assignmentid)).execute();
if (assignmentList.length === 0) {
const state: string = "null";
return state;
}
return assignmentList;
}

async function writeAssignment(assignment:Assignment) {
const date = new Date().toUTCString(); // notiible bug
await db.insert(assignments).values([{ id: assignment.id, name: assignment.name, dateCreated: date }]).execute();
}

export async function coreDB(assignment:Assignment){
const id = assignment.id
const state = await checkAssignmentState(id);
if (state === "null") {
await writeAssignment(assignment);
}
else {
return state;
}
}

try{
const output = await db.select().from(assignments).execute();
console.log(output)
}
catch(error){
console.log(error);
}
No description
4 Replies
Angelelz
Angelelz10mo ago
This seems like a connection issue. I don't think it's related to drizzle.
thehi198
thehi19810mo ago
Thanks any ideas to where i can start? have tested the libsql package independently and receiving the same error removed from cache and reinstalled as well
Angelelz
Angelelz10mo ago
try without bun to see tsx run src/dbUtils.ts Can you connect to that server any other way?
thehi198
thehi19810mo ago
i got it resolved, it seems I confused the connection URL i was using thank you so much for your help
Want results from more Discord servers?
Add your server