Giter Club home page Giter Club logo

lucid's People

Contributors

drewridley avatar itsezc avatar soya-miruku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lucid's Issues

Feature Request: Automatic field type infer

Preliminary checklist

  • I understand that all communication must be in English
  • I read the Documentation
  • I read the Contributing guide
  • I agree to follow the Code of Conduct
  • I searched the issues and discussions but couldn't find anything (or linked relevant results below)

Problem

Its a bit verbose to pass type definitions to the @Field() decorator of the target Model, an example of this is:

@Table({ edge: true })
export class SubsidaryOf extends Model {
    @Field({ name: 'in' })
    inside!: Organization

    @Field<SubsidaryOf>({
        assert: ({ inside }, $value) => $value !== inside,
    })
    out!: Organization
}

The @Field() for out should automatically infer the type of SubsidaryOf instead of Organization

Solution

This is currently blocked by microsoft/TypeScript#37300

Resources:
https://stackoverflow.com/questions/71218773/how-typescript-method-decorator-factory-get-target-class-type

Alternatives

No response

Contribution

Yes, I will work on a PR

Keywords

types, infer, field, decorator

Feature Request: Tests for client

Preliminary checklist

  • I understand that all communication must be in English
  • I read the Documentation
  • I read the Contributing guide
  • I agree to follow the Code of Conduct
  • I searched the issues and discussions but couldn't find anything (or linked relevant results below)

Problem

The Surreal DB client is not tested, and therefore may fail in production both the WS and REST implementations should ship with unit tests.

Solution

Implement tests with Bun on the client package.

Alternatives

No response

Contribution

Yes, I will work on a PR

Keywords

tests, client, surreal, db

Feature Request: reference relations in Models

Preliminary checklist

  • I understand that all communication must be in English
  • I read the Documentation
  • I read the Contributing guide
  • I agree to follow the Code of Conduct
  • I searched the issues and discussions but couldn't find anything (or linked relevant results below)

Problem

It would be very intuitive where a Model can reference relations, here is an example use case:

@Table({ name: 'follows', edge: true })
export class Followers extends Model 
{
    @Field({ name: 'in' })
    inside!: User;
    out!: User;
}

@Table({ name: 'follows', edge: true })
export class Following extends Model 
{
    @Field({ name: 'in' })
    inside!: User;

    out!: User;
}

@Table<User>({
    name: 'user',
    permissions: ({ username }) => [
        [['CREATE', 'UPDATE', 'SELECT'], true],
        ['DELETE', AdminScope]
    ],
    auditable: true,
})
export class User extends Model
{
    @Field({ index: 'unique' })
    username: string;

    @Field({ assert: 'email', name: 'email_address', index: 'unique' })
    email?: string;

    bestFriend?: User;

    followers?: Followers[];

    following?: Following[];
}

being able to select, relational fields via the select method
eg. User.select(['username', 'followers', 'following']).build()
SELECT username, <-follows<-user as followers, ->follows->user as following FROM user
also to be able to fetch relational fields via the fetch method
eg. User.select(['username', 'followers', 'following']).fetch(['followers', 'following']).build();

there are several issues which need to be addressed

  1. the schema generator must know how to handle the relational fields (i.e do not mistake them for record fields)
  2. the select builder must also know how to differentiate between relational and record fields

one solution could be to create a new decorator called @relational
this decorator would be used to decorate the relational fields
@relational(Followers) (could also potentially add more props to this decorator)
the schema generator would then know to ignore these fields
the select builder would also know to ignore these fields

another solution could be to add a new property to the @field decorator
eg. @field({ relation: Followers })

a third solution could be to expand the current select method to accept an instance of a select builder
eg. User.select(['username')]).select(Followers.select())
or expand the in, out logic to handle the relational query

However, further investigation is needed on how one might reference deeply nested relations and an alternative API maybe necessary than the one currently suggested.

Solution

Relation references could be tagged with a decorator i.e. @FieldRelation()

and therefore be usable in Models:

export class Account extends Model
{
     @FieldRelation({ direction: 'in' })
     friends: Friend[]
}

Alternatives

No response

Contribution

No, I cannot contribute further

Keywords

relations, model, query, API

FR: Multiple conditions on comparison

Currently it isn't possible to have:

Account.select()
   .where({
      location: {
         inside: {
            type: 'Point',
            coordinates: [21, 21]
         },
         outside: {
            type: 'Point',
            coordinates: [22, 22]
         }
      }
})
.build()
Account.select()
   .where({
      username: {
         endsWith: 'ends',
         startsWith: 'starts'
      }
   })
.build()

As only one comparison generates a valid query.

Feature Request: dynamic return types

Preliminary checklist

  • I understand that all communication must be in English
  • I read the Documentation
  • I read the Contributing guide
  • I agree to follow the Code of Conduct
  • I searched the issues and discussions but couldn't find anything (or linked relevant results below)

Problem

Currently, the return types are linked to the Model of which they are called by i.e. Account.select() would return Account[], however in some cases the developer may only select a few fields i.e. username and password and therefore returning the full type may be obsolete and provide types which are otherwise invalid.

Additionally, some field types may be sub queries, these should also be handled adequately.

Solution

The builder needs to be aware of such functionality and ensure that only the selected field types are returned.

Alternatives

No response

Contribution

Yes, I will work on a PR

Keywords

dynamic, queries, return, types

Bug: primitives array in `Model` doesn't parse

Currently, primitive arrays i.e. string[] or number[] is not parsed by the schema generator, further investigation should be undertaken to see if GeoPoint[] and other similar types can be generated.

Default From value?

currently when you do a select query such as
Account.select(['email', 'id']).where({ email: '[email protected]' }).build(); it does not infer the table name, i think it should do so in such a case, and if a user decides to override they can add the from query

not sure if this would be a case of just adding
query = query.concat(' ', 'FROM ', this.query_table || this.query_from); in the select builder, but yeah just wanted to raise it.

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.