Giter Site home page Giter Site logo

Comments (5)

kettanaito avatar kettanaito commented on May 21, 2024 1

Hey, @camchenry. Thank you for yet another suggestion!

Would T | null work for your use case? It'd be great to align the returned value, and we do use null for update/delete operations already:

data/src/glossary.ts

Lines 136 to 140 in f8da857

update(
query: QuerySelector<Value<Dictionary[ModelName], Dictionary>> & {
data: Partial<UpdateManyValue<Dictionary[ModelName], Dictionary>>
},
): EntityInstance<Dictionary, ModelName> | null

from data.

marcosvega91 avatar marcosvega91 commented on May 21, 2024 1

I have noticed this some day ago and put it in the pr #67. Today i'll rebase the branch

from data.

camchenry avatar camchenry commented on May 21, 2024 1

Yeah, T | null would work for me, and I'd imagine others as well. For pretty much all intents and purposes, I'd treat null and undefined interchangeably. For me, the main thing is being able to use the ??, and ?. operators to handle nullish values seamlessly, as well as doing a check like:

const entity = db.entity.findFirst(...);
if (!entity) {
  throw new Error(); // or return 404
}
// entity is now guaranteed to not be null/undefined

Thinking about it a little more though, this should probably only apply to the findFirst function, because it returns the entity directly rather than an array of entities. Because findFirst is analogous to Array.find and findMany is analogous to Array.filter?

from data.

kettanaito avatar kettanaito commented on May 21, 2024 1

Agree on that: let's retain findMany returning an empty array in the case when no entities matched the query. I find it a more pleasant data type to work with (both results.length and results.map are intuitive on empty results).

from data.

kettanaito avatar kettanaito commented on May 21, 2024

I believe with @67 merged findFirst and findMany now return the expected types:

data/src/glossary.ts

Lines 129 to 141 in 5cc1d73

/**
* Find a first entity matching the query.
*/
findFirst(
query: QuerySelector<Value<Dictionary[ModelName], Dictionary>>,
): Entity<Dictionary, ModelName> | null
/**
* Find multiple entities.
*/
findMany(
query: WeakQuerySelector<Value<Dictionary[ModelName], Dictionary>> &
BulkQueryOptions,
): Entity<Dictionary, ModelName>[]

from data.

Related Issues (20)

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.