question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Edge case with field name case conversion

See original GitHub issue

If I have a field named flightID for example, it’s returned from DB as flightId:

import { DataTypes, Database, Model } from "https://deno.land/x/denodb/mod.ts";

const db = new Database("sqlite3", {
  filepath: "temp.db",
});

class Flight extends Model {
  static table = "flights";
  static timestamps = true;

  static fields = {
    flightID: {
      primaryKey: true,
      autoIncrement: true,
    },
    departure: DataTypes.STRING,
  };
}

db.link([Flight]);

await db.sync({ drop: true });

await Flight.create([
  {
    departure: "Paris",
  },
  {
    departure: "London",
  },
]);

console.log(await Flight.all());

Output

[
  {
      flightId: 1,
      departure: "Paris",
      createdAt: "2020-06-06 15:03:54",
      updatedAt: "2020-06-06 15:03:54"
    },
  {
      flightId: 2,
      departure: "London",
      createdAt: "2020-06-06 15:03:54",
      updatedAt: "2020-06-06 15:03:54"
    }
]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Cotehcommented, Jun 15, 2020

Hey man that’s no problem, so sorry I didn’t get back! I wanted to get around to this at some point but was wrapped up in other projects. What you proposed was a good solution!

On Jun 15, 2020, at 8:02 AM, Arnaud Dellinger <notifications@github.commailto:notifications@github.com> wrote:

James, in case you ever see this, I will take over as it’s been raised by another issue. I bet you’re just busy so no worries 😃

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/eveningkid/denodb/issues/43#issuecomment-644086715, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAY74PRY5WEYRICVFOVFKFTRWYEUTANCNFSM4NWCMB4Q.

1reaction
Cotehcommented, Jun 6, 2020

Actually, wouldn’t mind taking a stab at it! 😃

We can have the field name be automatically converted by default (as it currently does) but the fieldNames property can be provided to Model if you want to override any of them, like what you showed above. What do you think?

On Jun 6, 2020, at 1:02 PM, Arnaud Dellinger <notifications@github.commailto:notifications@github.com> wrote:

It’s fair, and I think in the long term, the implementation should be different.

Right now it is formatted by default. However I think it would be better to have something like that instead:

// In Model, computed and based on static fields fieldNames = { // [Original field name (from client side)]: database field name, flightId: ‘flight_id’, };

This would then allow to override default formatting field names, just as in your case.

Right now, the original field name is lost in translation…as it expects your field name to follow naming conventions. But yes, it might create some confusion in case the name is different.

So two options:

  • I can add a comment about this in the documentation
  • We can add this now in the code

I just feel a little tired right now, working on this every day. I need a break. So this might have to wait unless you want to work on it, but no pressure.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/eveningkid/denodb/issues/43#issuecomment-640090080, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAY74PUKL2NQBYLSVPIOSIDRVJZEBANCNFSM4NWCMB4Q.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the case of text - Microsoft Support
This formula converts the name in cell A2 from uppercase to proper case. To convert the text to lowercase, type =LOWER(A2) instead. Use...
Read more >
Edge Cases to Keep in Mind. Part 1 - Text - Droids On Roids
Conversion from one letter case to another is quite a common operation. Casing might seem trivial – one character is just converted (mapped)...
Read more >
How to find and deal with edge cases in UX design | UX Planet
Edge cases like this can happen, but the probability is very low. We can fix this by enlarging the input field on hover...
Read more >
Dealing with SQL server datetime edge cases - Stack Overflow
@Oded: WHERE CONVERT( VARCHAR, Dates, 101 ) >= GETDATE( ) - 1 (i) it does not use any indexes (ii) it fails on...
Read more >
Expecting the Unexpected: Edge Cases in Web Design
Consider the case of MS Word's autocorrect feature, which automatically converts “hte” to “the”. This autocorrection might fail in the tiny ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found