GithubHelp home page GithubHelp logo

Add support for DateTime type about floor HOT 6 CLOSED

pinchbv avatar pinchbv commented on July 21, 2024 4
Add support for DateTime type

from floor.

Comments (6)

vitusortner avatar vitusortner commented on July 21, 2024 5

I've thought about introducing type converters similar how Room handles these conversions. This would open up the possibility of persisting data of custom date implementations, for instance. What are your thoughts?

from floor.

megasoft78 avatar megasoft78 commented on July 21, 2024 2

I found a workaround for now using the dart built-in features :

  • var milliseconds = DateTime.now().millisecondsSinceEpoch
  • DateTime.fromMillisecondsSinceEpoch(milliseconds)

Not sure why DateTime is not supported. I think SQLite support it as format.
@vitusortner Do you have some technical limitation here? Why do you need to convert?

from floor.

IanDarwin avatar IanDarwin commented on July 21, 2024 1

@vitusortner: Further to the above:

For example, whenever an enum value should get stored.

For the special case of enums, wouldn't it make sense to have floor simply store in an int column, and just convert using myEnum.index and myEnum.values[n]?

One step up would be to copy the idea from JPA and use an annotation to allow mapping by user's choice of int value or by string name (FWIW, JPA uses @Enumerated(EnumType.STRING) or EnumType.ORDINAL; ORDINAL is the default there). It's well known there that ordinal is more efficient but does mean you can't add new values to the enum except at the end.

This would be simpler than fully implementing type converters and could maybe get in sooner? But meanwhile I've had to convert my entity to use ints for dates (as you suggest) and for enums.

from floor.

vitusortner avatar vitusortner commented on July 21, 2024

DateTime is not supported by sqflite (the database access layer).

Type converters might seem like an overkill for such an easy mapping between milliseconds and Dart's DateTime. They surely simplify the interaction with the database. Nevertheless, type converters come in even more handy when thinking about other conversions. For example, whenever an enum value should get stored. It's nicer to just define a type converter in one place and let it do its magic automatically without calling its functions manually.

from floor.

megasoft78 avatar megasoft78 commented on July 21, 2024

Yes, make sense. :)

from floor.

vitusortner avatar vitusortner commented on July 21, 2024

It's not planned to support DateTime out of the box for now. Same for enums. Instead, type converters will be introduced soon which will solve these problems. Follow the progress and discussion in #165.

from floor.

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.