Giter Site home page Giter Site logo

dgraph-orm's People

Contributors

andrejpavlovic avatar dependabot[bot] avatar haseebrabbani avatar lhr0909 avatar necmttn avatar nickcaminer avatar osmanmesutozcan avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dgraph-orm's Issues

Support Facet Alias

Currently we don't support mapping facet alias in the ObjectMapper. However, if this feature is important, we can try to find a way to support it.

New version 0.1.17-alpha3 generates a bad mutation string when Facet contains falsy values

@osmanmesutozcan

I used the 0.1.15 version and the new 0.1.17-alpha3 add test and found that the generated code is different, when the facetvalue is 0 or undefined, the 0.1.17-alpha3 will go wrong

0.1.15

it('should add the correct facet', function() {
    class OrderFacet {
      constructor({ order, width }: { order?: number; width?: number } = {}) {
        if (order != null) {
          this.order = order;
        }
        if (width != null) {
          this.width = width;
        }
      }
      @Facet()
      order?: number;

      @Facet()
      width?: number;
    }

    @Node()
    class Person {
      @Uid()
      id: string;

      @Property()
      name: string;

      @Predicate({ type: () => Person, facet: OrderFacet })
      friends: IPredicate<Person, OrderFacet>;
    }

    const lim = new Person();
    lim.name = 'Lim';
    const nick = new Person();
    nick.name = 'Nick';

    lim.friends.withFacet(new OrderFacet({ order: 0 })).add(nick);
    nick.friends.withFacet(new OrderFacet({ order: 1, width: 200 })).add(lim);

    console.log(MutationBuilder.getSetNQuadsString(lim).quads);
// _:b83db4fc12819b2a <dgraph.type> "Person" .
// _:b83db4fc13060b01 <dgraph.type> "Person" .
// _:b83db4fc12819b2a <Person.friends> _:b83db4fc13060b01 (order=0) .
// _:b83db4fc13060b01 <Person.friends> _:b83db4fc12819b2a (order=1,width=200) .
  });

0.1.17-alpha3

  it('should add the correct facet', function() {
    class OrderFacet {
      constructor({ order, width }: { order?: number; width?: number } = {}) {
        if (order != null) {
          this.order = order;
        }
        if (width != null) {
          this.width = width;
        }
      }
      @Facet()
      order?: number;

      @Facet()
      width?: number;
    }

    @Node()
    class Person {
      @Uid()
      id: string;

      @Property()
      name: string;

      @Predicate({ type: () => Person, facet: OrderFacet })
      friends: IPredicate<Person, OrderFacet>;
    }
    const transaction = TransactionBuilder.build();

    const lim = transaction.nodeFor(Person);
    lim.name = 'Lim';
    const nick = transaction.nodeFor(Person);
    nick.name = 'Nick';

    lim.friends.withFacet(new OrderFacet({ order: 0 })).add(nick);
    nick.friends.withFacet(new OrderFacet({ order: 1, width: 200 })).add(lim);

    console.log(transaction.getSetNQuadsString());
// _:b83db8df3d812bd0 <dgraph.type> "Person" .
// _:b83db8df3d812bd0 <Person.name> "Lim"^^<xs:string> .
// _:b83db8df3d8c3f6b <dgraph.type> "Person" .
// _:b83db8df3d8c3f6b <Person.name> "Nick"^^<xs:string> .
// _:b83db8df3d812bd0 <Person.friends> _:b83db8df3d8c3f6b (order=undefined,width=undefined) . <- Facet generation error
// _:b83db8df3d8c3f6b <Person.friends> _:b83db8df3d812bd0 (order=1,width=200) .
  });

Incorrect type definition

The supported RDF datatypes and the corresponding internal type in which the data is stored are as follows.

Storage Type Dgraph type
xs:string string
xs:dateTime dateTime
xs:date datetime
xs:int int
xs:boolean bool
xs:double float
xs:float float
geo:geojson geo
xs:password password
http://www.w3.org/2001/XMLSchema#string string
http://www.w3.org/2001/XMLSchema#dateTime dateTime
http://www.w3.org/2001/XMLSchema#date dateTime
http://www.w3.org/2001/XMLSchema#int int
http://www.w3.org/2001/XMLSchema#boolean bool
http://www.w3.org/2001/XMLSchema#double float
http://www.w3.org/2001/XMLSchema#float float

override dgraph.type

Needs to be able to override dgraph.type to fit in existing initialized data.

MutationBuilder.getSetNQuadsString becomes slow after running multiple times

  it('performance Testing', () => {
    @Node()
    class Cell {
      @Uid()
      uid: string;

      @Predicate({ name: 'from_row', type: () => Row })
      fromRow: IPredicate<Row>;

      @Predicate({ name: 'from_column', type: () => Column })
      fromColumn: IPredicate<Column>;
    }

    @Node()
    class Row {
      @Uid()
      uid: string;

      @Predicate({ name: 'has_cell', type: () => Cell })
      hasCell: IPredicate<Cell>;
    }

    @Node()
    class Column {
      @Uid()
      uid: string;

      @Predicate({ name: 'has_cell', type: () => Cell })
      hasCell: IPredicate<Cell>;
    }

    const column = new Column();

    let i = 0;
    let first20 = 0;
    let last20 = 0;
    let time = 0;
    const times = 5000;

    while (i++ < times) {
      const cell = new Cell();
      const row = new Row();

      cell.fromRow.add(row);
      cell.fromColumn.add(column);

      row.hasCell.add(cell);
      column.hasCell.add(cell);

      const _time1 = Date.now();
      MutationBuilder.getSetNQuadsString(cell);
      const _time2 = Date.now();
      time += _time2 - _time1;
      if (i < 21) {
        first20 += _time2 - _time1;
      }
      if (i > 4980) {
        last20 += _time2 - _time1;
      }
    }

    console.log('duration: ', time);
    console.log('avg: ', time / times);
    console.log(`first 20: ${first20}, avg: ${first20 / 20}`);
    console.log(`last 20: ${last20}, avg: ${last20 / 20}`);
  });

Issues with Delete

  • predicate delete current does not remove the underlying model after generating delete diff
  • provide a deleteAll API

Need a way to delete only edge between two nodes

Sample data:

const data = [
  {
    uid: '0x1',
    'Person.name': 'John'
  },
  {
    uid: '0x2',
    'Person.name': 'Jane',
    'Person.friends': [
      {
        uid: '0x1',
      }
    ]
  }
];

How do I delete only the friends edge between Jane and John?
I would just like to generate the following nquad: <0x2> <Person.friends> <0x1>, but if I call anything like jane.friends.delete(john); I get more than just that edge deleted:

<0x1> * * .
<0x2> <Person.friends> <0x1> .

Need to initialize association when new object

When we use an existing object to associate a new object, the edge association is not initialized, so it is undefined, which makes it impossible to add an association.

it('should initialize new object', function() {
    @Node()
    class Person {
      @Uid()
      id: string;

      @Property()
      name: string;

      @Predicate({ type: () => Person })
      friends: IPredicate<Person>;
    }
    const transaction = TransactionBuilder.build();

    // This is a new data
    const nick = transaction.nodeFor(Person);
    nick.name = 'Nick';

    // This is an existing data
    const c = new Person();
    c.id = '0x12';
    c.name = 'c';

    nick.friends.add(c);
    c.friends.add(nick); // <-Cannot read property 'add' of undefined

    console.log(transaction.getSetNQuadsString());
  });

Support recursive temporary id

 it('should support the same recursive ID', ()=>{
    //#region class
    @Node()
    class Cell{
      @Uid()
      uid: string;

      @Predicate({ name: 'from_row', type: () => Row })
      fromRow: Predicate<Row>;

      @Predicate({ name: 'from_column', type: () => Column })
      fromColumn: Predicate<Column>;
    }

    @Node()
    class Row{
      @Uid()
      uid: string;

      @Predicate({ name: 'has_cell', type: () => Cell })
      hasCell:  Predicate<Cell>;
    }

    @Node()
    class Column{
      @Uid()
      uid: string;
      
      @Predicate({ name: 'has_cell', type: () => Cell })
      hasCell:  Predicate<Cell>;
    }
    //#endregion

    const cell = new Cell();
    const row = new Row();
    const column = new Column();

    cell.fromRow.add(row);
    cell.fromColumn.add(column);

    row.hasCell.add(cell);

    const rq = MutationBuilder.getSetNQuads(row);

    const rowId = rq.nodeMap.get(row)?.value;
    const fromRowId = (rq.quads as Quad[]).find(r=>r.predicate.id === 'from_row')?.object.value;

    expect(rowId).toEqual(fromRowId);
  });

Remove is invalid

When I delete the relationship of an edge, check that the relationship still exists after using the remove function

const recordReferenceColumn = column.hasRecordReferenceColumn.get();
if (recordReferenceColumn.length) {
      column.hasForeignLookupColumn.remove(recordReferenceColumn[0]);
}

define custom `dgraphType` result in unexpected schema

schema define:

@Node({
  dgraphType: 'Post'
})
export class PostEntity {
  @Property({
    type: PropertyType.String
  })
  title: string;
}

schema build output:

type Post {
  PostEntity.title: string // prefix is classname and type restrict  is unnecessary.
}
PostEntity.title: string .

expect output:

type Post {
  Post.title
}
Post.title: string .

It works well, but the result is not expected.

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.