Comments (44)
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.
@greenrobot When is this feature expected to be available ?
from greendao.
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.
the feature updates?
from greendao.
@greenrobot any updates ?
from greendao.
I have another suggestion for this topic, see discussion
from greendao.
+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.
Another +1 it would make some stuff easier indeed ...
from greendao.
Another +1 (sad to hear this request have been added 3 years ago :-( )
from greendao.
+1 for this, It is good to have default values.
Why not sure about this?!!!!
from greendao.
+1 so that all properties should have default values
from greendao.
+1 I also want this feature.
from greendao.
+1 this is a must.
from greendao.
+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.
+1. Also primitive type like int
instead of Integer
will be welcome.
from greendao.
+1 for this feature.
I'd rather not set the defaults in the constructor with the generator overwriting code.
from greendao.
+1 for this feature.
from greendao.
+1 this one is really missing.
from greendao.
+1 I also want this feature.
from greendao.
+1 for this feature!
from greendao.
+1 a much needed feature
from greendao.
+1 for this feature
from greendao.
I love greendao. please
from greendao.
+1 Please add
from greendao.
+1 I also want this feature.
from greendao.
+1 needed for alot of us please add it
from greendao.
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.
having this in the constructor will not prevent putting NULL values.
how exactly is this adding queries?
from greendao.
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.
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.
Hope it will be realised soon. Highly required thing.
from greendao.
+1 for this, any news?
from greendao.
+1 , come on
from greendao.
+1
from greendao.
+1
from greendao.
+1 It's been 2years now..come on
from greendao.
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.
@greenrobot-team
please provide me a clear example.
thank you very much
from greendao.
@greenrobot you meat get default in java code, actually the default value is not in databases file ?
from greendao.
@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.
+1
from greendao.
Hey is this gonna happen or what?
from greendao.
+1
from greendao.
+1
from greendao.
Related Issues (20)
- incompatible gradle-6.5-bin.zip HOT 1
- Blocker issue in Sonarqube HOT 2
- Openharmony application HOT 1
- 一对多的关系表映射问题 HOT 3
- disk image is malformed (Sqlite code 11 SQLITE_CORRUPT) HOT 1
- How to do data filling, such as populating data from a database in assets into an app HOT 1
- Read this first! Check out our new database
- kotlin version problem HOT 1
- Can I use greenDao in multiple libraries? ------ Look forward to your reply HOT 1
- 什么时候支持协程 HOT 1
- Will a new version be released in the future when a bug occurs in the project? HOT 1
- DaoGenerator.getConfiguration Exception HOT 2
- Lambda 表达式报错 HOT 2
- The project encountered errors after updating Gradle Version 7.6.1 to Gradle Version 8.0+ HOT 40
- when use ’group by‘ ,the result is not expected HOT 1
- Unable to load class 'org.greenrobot.greendao.codemodifier.FormattingOptions'.
- DaoMaster class error HOT 1
- error: cannot find symbol db.execSQL("CREATE TABLE " + constraint + "\ symbol: method makeConcatWithConstants(Lookup,String,MethodType,String) location: interface StringConcatFactory HOT 1
- ... not supported with the configuration cache HOT 1
- net.zetetic:android-database-sqlcipher:3+ update 4+ DaoException HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from greendao.