Git Product home page Git Product logo

Comments (44)

greenrobot avatar greenrobot commented on July 18, 2024 31

For greenDAO 3, it might look like this:

@Property(defaultValue="true")
boolean valid;

@Property(defaultValue="new Date()")
Date created;

So a default value would simply be a string pasted where needed (e.g. constructor, if that proves to be sufficient for most people).

from greendao.

iballan avatar iballan commented on July 18, 2024 8

@greenrobot When is this feature expected to be available ?

from greendao.

iballan avatar iballan commented on July 18, 2024 5

since the defaults managed by Database is Not an option and it will affect the performance. You may add it to the contractor as well.

what I do for now:

public SurfaceEntity() {
    // KEEP CONSTRUCTOR-DEFAULT - put your custom constructor code here
    created = new Date();
    myOtherDefaultValue = false;
        SurfaceIsTransparent = false;
    // KEEP CONSTRUCTOR-DEFAULT END
}

public SurfaceEntity(Long id) {
    // KEEP CONSTRUCTOR-ID - put your custom constructor code here
    this(); // call default to initialize with default values
    // KEEP CONSTRUCTOR-ID END
    this.id = id;
}

you may add function for the properties to this for us.

something like:

surfaceEntity.addBooleanProperty("SurfaceIsTransparent")
 .setDefaultBool(false);

This is just a suggestions if it is possible.

Thank you

from greendao.

SpiritMan avatar SpiritMan commented on July 18, 2024 4

the feature updates?

from greendao.

umesh0492 avatar umesh0492 commented on July 18, 2024 1

@greenrobot any updates ?

from greendao.

matecode avatar matecode commented on July 18, 2024

I have another suggestion for this topic, see discussion

from greendao.

shroff avatar shroff commented on July 18, 2024

+1 on this feature.

In general, having a more flexible KEEP mechanism would a large majority of my issues. I think that KEEP within methods is one way to do it, but I would personally love to have a way to override generated methods, including constructors. Accidental overrides could be avoided with annotations, if that's a concern.

Example use cases:

  • Add initialization inside constructors
  • Create property representations are stored in a certain format in the DB, but accessed as Objects from code.

from greendao.

 avatar commented on July 18, 2024

Another +1 it would make some stuff easier indeed ...

from greendao.

glureau avatar glureau commented on July 18, 2024

Another +1 (sad to hear this request have been added 3 years ago :-( )

from greendao.

saeedsq avatar saeedsq commented on July 18, 2024

+1 for this, It is good to have default values.
Why not sure about this?!!!!

from greendao.

vodkhang avatar vodkhang commented on July 18, 2024

+1 so that all properties should have default values

from greendao.

jongha avatar jongha commented on July 18, 2024

+1 I also want this feature.

from greendao.

hemdatd avatar hemdatd commented on July 18, 2024

+1 this is a must.

from greendao.

Hardik4560 avatar Hardik4560 commented on July 18, 2024

+1. Yes, this is required as Double, Integer, Float, Boolean and other Wrapper datatypes are null when retrieved. It should be 0 or false in case of Boolean. This is highly required feature. GreenDao is a very good library and I don't wanna stop using it for such small features missing.

from greendao.

adamkotkowski avatar adamkotkowski commented on July 18, 2024

+1. Also primitive type like int instead of Integer will be welcome.

from greendao.

aishpant avatar aishpant commented on July 18, 2024

+1 for this feature.
I'd rather not set the defaults in the constructor with the generator overwriting code.

from greendao.

olegflo avatar olegflo commented on July 18, 2024

+1 for this feature.

from greendao.

hkokocin avatar hkokocin commented on July 18, 2024

+1 this one is really missing.

from greendao.

zeng1990java avatar zeng1990java commented on July 18, 2024

+1 I also want this feature.

from greendao.

caiolopes avatar caiolopes commented on July 18, 2024

+1 for this feature!

from greendao.

akki-123 avatar akki-123 commented on July 18, 2024

+1 a much needed feature

from greendao.

shivakumars avatar shivakumars commented on July 18, 2024

+1 for this feature

from greendao.

hanhnd76 avatar hanhnd76 commented on July 18, 2024

I love greendao. please

from greendao.

source-creator avatar source-creator commented on July 18, 2024

+1 Please add

from greendao.

ButSoft avatar ButSoft commented on July 18, 2024

+1 I also want this feature.

from greendao.

iballan avatar iballan commented on July 18, 2024

+1 needed for alot of us please add it

from greendao.

greenrobot avatar greenrobot commented on July 18, 2024

OK, let's collect some requirements!

Something I really want to avoid is to use defaults managed by the database. Why? Because it would require querying the database after inserts/updates, which would add complexity and slowness. Not an option.

What would be pretty easy to implement is setting fields in an entity's default constructor to default values. Would that be an option?

from greendao.

yishai-glide avatar yishai-glide commented on July 18, 2024

having this in the constructor will not prevent putting NULL values.
how exactly is this adding queries?

from greendao.

greenrobot avatar greenrobot commented on July 18, 2024

If the dev really wants to override with null, then why not?

The problem with letting the DB do it, is that we only might assume we have the current state (a certain default value). For example, if a dev updated the default value, but forgot about schema migration, greenDAO would have the new default value, but the DB would be actually using the old one. So this is dangerous. To prevent this, it would be an option to refresh the entity from the DB after insert/update to ensure a consistent state.

from greendao.

greenrobot avatar greenrobot commented on July 18, 2024

Btw, if the problem is that you have nulls because of fields are of non-primitive types (e.g. Long/Integer/Float/Double): this is a different topic! Please be aware that you also can use primitive types. In that case, "defaults" will be 0 and not null. If you use the generator project, you need to enable it using notNull() on your property.

from greendao.

HeyAlex avatar HeyAlex commented on July 18, 2024

Hope it will be realised soon. Highly required thing.

from greendao.

wrestlingcarbonapple avatar wrestlingcarbonapple commented on July 18, 2024

+1 for this, any news?

from greendao.

chentao7v avatar chentao7v commented on July 18, 2024

+1 , come on

from greendao.

vostreltsov avatar vostreltsov commented on July 18, 2024

+1

from greendao.

TheCrafter avatar TheCrafter commented on July 18, 2024

+1

from greendao.

Hardik4560 avatar Hardik4560 commented on July 18, 2024

+1 It's been 2years now..come on

from greendao.

greenrobot-team avatar greenrobot-team commented on July 18, 2024

Just to note: with greenDAO 3 it is easy to have a custom constructor (annotate the generated one with @Keep) where you could set your default values. You may also modify your getters and setters to set or return some default value if appropriate. -ut

from greendao.

BigGitWorld avatar BigGitWorld commented on July 18, 2024

@greenrobot-team
please provide me a clear example.
thank you very much

from greendao.

liujigang avatar liujigang commented on July 18, 2024

@greenrobot you meat get default in java code, actually the default value is not in databases file ?

from greendao.

KhalidElSayed avatar KhalidElSayed commented on July 18, 2024

@greenrobot @greenrobot-team
So how to solve the default value issue when it comes to migration?

Caused by: android.database.sqlite.SQLiteConstraintException: NOT NULL constraint failed: Books.IS_MOST_READ

your solution is not working and not clear, you don't even provide us with a working example!

from greendao.

sanekyy avatar sanekyy commented on July 18, 2024

+1

from greendao.

samuelowino avatar samuelowino commented on July 18, 2024

Hey is this gonna happen or what?

from greendao.

ZheGuangZeng avatar ZheGuangZeng commented on July 18, 2024

+1

from greendao.

silexion avatar silexion commented on July 18, 2024

+1

from greendao.

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.