Interactions-as-a-Service / d1-orm

A simple, strictly typed ORM, to assist you in using Cloudflare's D1 product
https://docs.interactions.rest/d1-orm/
Apache License 2.0
161 stars 10 forks source link

Prefer single quotes over double quotes #60

Closed carsonfarmer closed 1 year ago

carsonfarmer commented 1 year ago

Describe the bug When specifying a string defaultValue for a given model, the value is "encoded" with double quotes in the create statement. While this is technically ok with SQLite, it is actually not best practice (https://www.sqlite.org/quirks.html). While I understand that this is not a high-priority issue, it is causing downstream issues for me when use this for local development, so I thought I would submit an issue in case it is hitting anyone else. I'm happy to submit a PR for this (tiny) fix, if that would be accepted.

The following section of a model:

...
name: {
  type: DataTypes.STRING,
  notNull: true,
  defaultValue: "John Doe",
},
...

runs into this on line 138 of current main:

defaultStr = `"${column.defaultValue}"`;

Expected behavior

That line should probably be

defaultStr = `'${column.defaultValue}'`;
Skye-31 commented 1 year ago

Hi @carsonfarmer.

Thanks for the issue! This should be resolved in v0.7.2.

carsonfarmer commented 1 year ago

Amazing, you rock @Skye-31! Thanks for the quick fix, and for this library :)