objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
918 stars 116 forks source link

$ in the property name eror in the objectbox.g.dart file #620

Closed nathanael540 closed 2 weeks ago

nathanael540 commented 1 month ago

Is there an existing issue?

Build info

Steps to reproduce

just create an entity with a $ at the beginning of one of its properties:

class Plan {
  @Id()
  int id;

  @Unique()
  String $uid;

  String name;
}

Expected behavior

Generated objectbox.g.dart file with correct escaping like

obx_int.ModelProperty(
             id: const obx_int.IdUid(2, 2870122101975113894),
             name: '\$id',
             type: 9,
             flags: 2080,
             indexId: const obx_int.IdUid(1, 6518471420466642677)
)

Actual behavior

Generated code does not have character escaping:

obx_int.ModelProperty(
             id: const obx_int.IdUid(2, 2870122101975113894),
             name: '$id',
             type: 9,
             flags: 2080,
             indexId: const obx_int.IdUid(1, 6518471420466642677)
)

Code

Logs, stack traces

VSCode show the message on file: Undefined name 'id'. Try correcting the name to one that is defined, or defining the name.

greenrobot-team commented 3 weeks ago

Thanks for reporting! I'm surprised this is allowed, especially as you have shown it conflicts with the template dollar-sign syntax.

I can't really find any official guidance on allowed characters for variable names (except _ for private visibility), do you know any? A Stack Overflow answer hints that the dollar-sign is reserved for generated code. Still, the generator should maybe support this.

nathanael540 commented 2 weeks ago

So, im using objectbox with appwrite, and in appwrite the document ID are with $ on begin.

source

But, I create one new model with docId to avoid conflicts.