cashapp / sqldelight Goto Github PK
View Code? Open in Web Editor NEWSQLDelight - Generates typesafe Kotlin APIs from SQL
Home Page: https://cashapp.github.io/sqldelight/
License: Apache License 2.0
SQLDelight - Generates typesafe Kotlin APIs from SQL
Home Page: https://cashapp.github.io/sqldelight/
License: Apache License 2.0
Currently it's like:
sqlite/
com/
example/
data/
People.sq
Should be like:
sqlite/
com.example.data/
People.sq
Ideally queries and sql statements should format automatically with the intellij plugin
Working:
Annoying:
Missing:
As we discussed, we could go as far as generating the onUpgrade switch automatically. We'd probably want to create something like .sqm
files (for migration) which relax the one-table-per-file restriction and don't actually generate anything for them.
Lots to think about since this probably won't happen for a while.
IDEA 16 updated to support Java 8, but Android Studio (as of 2.0) is still based on IDEA 15. Once both IDEA and AS have a stable (or at least beta) release based on IDEA 16 we should point at the release artifact.
IDEA does this for regex, can we do it for the queries?
I think I remember kotlin doing this where if you are in a .kt
file in a project that does not have the kotlin gradle plugin applied it complains at you with an actionable dialog that will add the plugin for you. Would be nice if we did that same for .sq
files
Changed foobar
to foo_bar
and sources still had foobar
in create constant, mapper types were stilled named BlahFoobarBlah
. Had to cut and paste to trigger regeneration.
.sq files should support build variants as well as main/test distinctions
When generated code fails, copy/pasting the expected files around whenever they change isn't feasible long-term. Wire uses a script to re-generate all expected files from the latest master. This makes it easy to update while also providing exact representations for PR diffs.
Creates over-indented, mis-aligned lines after the first one.
String FEMALES = ""
+ "SELECT *\n"
+ " FROM users\n"
+ " WHERE gender = 'FEMALE'";
see title
Right now update methods just ask for the where statement, one possibility is having the statement look like a normal update:
setName =
UPDATE user
SET ...
WHERE user.name = 'Alec'
could just generate the string
String SET_NAME = "user.name = 'Alec'";
It could also be annotated with something that says its only applicable on the user table. In fact all queries could do that which would be cool, throw a lint error if its on the wrong table or something.
Right now enums are tricky to deal with, typically you have something like
females =
SELECT *
FROM users
WHERE users.gender = 'FEMALE'
the enum values could be auto-completed for the user. Need to be a bit careful since updating the name of the enum would break the db (and require a migration)
You could use ?? for array parameters and potentially make the whole thing type safe since we know about columns.
sql code as well as java
The class can only be accessed in subclasses of the enclosing class (since it is final
itself) which means there's no chance of collision. Should just be called Mapper
.
Pull it from the gradle.properties of the enclosing project by writing it somewhere that can be embedded in the plugin.
Also remove quotes around types when specified in CREATE TABLE so the types can be referenced (kind of) like Java.
import com.example.foo.Bar
// ...
balance Bar NOT NULL
Right now theres a lot of java dependencies. The generated code is only seen by the java compiler, not the kotlin one, and I imagine a lot of the java specific intellij plugin features dont work as well (class autocomplete/clickthrough, enum typecheck)
The important test case is duplicateColumnName
. For some reason the element passed in has a stop
index which is 2 sooner than it should be.
All put
methods can handle null
values.
When you change the name of the table/column in a .sq file it should also references to:
Model file field name
Model file method name
Marshal class method name
CREATE VIEW some_view AS ...
should give you the same IDE benefits of declaring a table (autocomplete, refactoring, etc.)
Ideally we resolve the query after the AS
and learn about the columns it shows too. Somewhat related to #36
_id
currently becomes Id()
method.
Adding a .sq file outside of expected /src/main/sqldelight directory throws exception that plugin doesn't catch. Intellij/Android Studio 'helpfully' suggests disabling plugin.
Minimum fix would cause an error balloon to display. Desired fix would be to present user with action to move new file to desired file structure.
Correctly illegal:
text TEXT NOT NULL
but incorrectly illegal:
text:
SELECT * FROM words WHERE things='text'
Columns give proper types to each key-value pair and remove a bunch of special casing internally.
This issue seems like it basically could just be titled: remove key/value support. I'm not sure we have to do anything in the lib after this switch.
Blocked by JetBrains/intellij-platform-gradle-plugin#50
Right now the runtime code lets you pick any type, but the underlying storage type is a BLOB which affects how things like sorting and filtering behave.
Test case: store java.util.Date as a unix timestamp (i.e., number) in the DB
ex:
create table stuff (
list_of_string CLASS('java.util.List<String>')
)
Example:
create table test (
text STRING NOT NULL
);
someSql =
SELECT *
FROM ....
someSql
should be find usages-able
If a sql_stmt inside the .sq file is a query, generate a custom mapper for it
If I refactor a custom column then the Marshal and Mapper for that column should also be refactored.
One of the column definitions will think it references the other table's column with the same name, when really it is the root of references for columns namespaced by its tables name, same goes for the other column
Should automatically populate package and have an empty create table statement.
Queries with parameters (aka question marks) should get methods (not constants) generated with type-inferred parameters.
forFirstName:
SELECT * FROM user WHERE first_name = ?
public static ?? forFirstName(String first_name) { ... }
Not sure what the return type should be since the query and its args are two instances passed to SqliteDatabase
. Maybe the method returns the String[]
and there's still a constant for the query string? Since this won't be implemented for a while we have time to think.
When you use the databinding plugin with sqldelight you'll get an exception like:
java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with UUID aadb8d7e-aeef-4415-ad2b-8204d6cf042e (expected ab35191a-1603-487e-b75a-479b831eaf6d or a legacy UUID).
This is because it uses com.tunnelvisionlabs:antlr4
instead of org.antlr:antlr4
. These both ship the same classes in the same package but are incompatible on the same classpath.
An issue has been filed with Google to switch at http://b.android.com/200925
Until a new android plugin is released, the following workaround can (maybe?) be used:
buildscript {
configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module('com.tunnelvisionlabs:antlr4') with module('org.antlr:antlr4')
}
}
}
}
We don't want to have to do this explicitly.
Need JetBrains/kotlin#820 (or something like it) to be released.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.