Libsql mapHranaError

Using Drizzle with Turso with the following schema and code and receiving a libsql error as shown. @libsql/[email protected] [email protected] [email protected] [email protected] [email protected]
//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
Angelelz12mo ago
This seems like a connection issue. I don't think it's related to drizzle.
thehi198
thehi198OP12mo 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
Angelelz12mo ago
try without bun to see tsx run src/dbUtils.ts Can you connect to that server any other way?
thehi198
thehi198OP12mo 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