Giter Club home page Giter Club logo

Comments (8)

hrueger avatar hrueger commented on July 17, 2024 1

I have multiple databases with hyphens in the name and the other ones work fine. So it's probably the hyphen in the table name.

from d1-manager.

JacobLinCool avatar JacobLinCool commented on July 17, 2024

I am not sure...

Is there any special character in the table name or column name? I may have forgotten to escape something...

from d1-manager.

hrueger avatar hrueger commented on July 17, 2024

The database is called prod-logs, the table logs-v1.
Here's the schema:

import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const logsTableV1 = sqliteTable("logs-v1", {
    id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),

    // Timestamp
    timestamp: integer("timestamp", { mode: "number" }).notNull(),

    // Request details
    method: text("method").notNull(),
    url: text("url").notNull(),
    statusCode: integer("statusCode").notNull(),
    duration: integer("duration").notNull(),

    // Location details
    ip: text("ip").notNull(),
    country: text("country"),
    regionCode: text("regionCode"),
    city: text("city"),

    // Service details
    microservice: text("microservice").notNull(),
    deployment: text("deployment").notNull(),
    environment: text("environment").notNull(),

    // User details
    customerSessionId: text("customerSessionId"),
    userId: text("userId"),
    superadminId: text("superadminId"),

    // Additional data
    data: text("data"),

    // Error details
    error: text("error"),
});

Maybe timestamp is a problem?

from d1-manager.

johtso avatar johtso commented on July 17, 2024

I'm guessing it's the hyphen in the database name

from d1-manager.

johtso avatar johtso commented on July 17, 2024

https://stackoverflow.com/a/3694305/311220

A table name with a hyphen would need to be quoted.

Definitely some places where it looks like that's not happening:
https://github.com/search?q=repo:JacobLinCool/d1-manager+prepare+table&type=code

from d1-manager.

moalamri avatar moalamri commented on July 17, 2024

Hi @JacobLinCool
Thank you for this great tool,
It seems that Cloudflare takes the table name directly from the URL param without adding anything to it.
By simply adding single quotes to the table name in the URL it will solve the issue e.g. /api/db/demodb/'table-name'/data?...
I have also tested the case with database names with hyphen and it seems that Cloudflare accept using hyphens in database names, but unlike table names it is processed from Cloudflare side and quoting the database name in URLs isn't necessary.
I have also tested columns and it has the same issue as with table names, I will make a PR with suggested fix for both table and column names.

from d1-manager.

JacobLinCool avatar JacobLinCool commented on July 17, 2024

Hello @moalamri

Thank you for your observations and contributions on PR #53.

I want to clarify that the /api/... endpoints are not part of the Cloudflare API; they are located here.

Since the database name is not presented in the SQL statement, it seems I forgot to escape the table name in the following places:

const { results } = await db.prepare(`SELECT COUNT(*) AS count FROM ${params.table}`).all<{

`SELECT ${select} FROM ${params.table}${where ? ` WHERE ${where}` : ""}${

`INSERT INTO ${params.table} (${Object.keys(data).join(", ")}) VALUES (${Object.keys(

`UPDATE ${params.table} SET ${Object.keys(data)

.prepare(`DELETE FROM ${params.table} WHERE ${where_sql(where)}`)

Maybe your utility functions should be applied to those places instead of replacing them in the URL at the frontend side. (It seems strange to see quotes in an URL)

from d1-manager.

moalamri avatar moalamri commented on July 17, 2024

Hey @JacobLinCool
My bad :) I looked into the component and really assumed they were calling Cloudflare.
I will work on it soon, maybe simplify it more by always applying escape to identifiers since they can accept a lot of special characters.

from d1-manager.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.