Giter Site home page Giter Site logo

cashapp / sqldelight Goto Github PK

View Code? Open in Web Editor NEW
5.9K 124.0 492.0 208.72 MB

SQLDelight - Generates typesafe Kotlin APIs from SQL

Home Page: https://cashapp.github.io/sqldelight/

License: Apache License 2.0

Java 0.56% Kotlin 96.16% HTML 0.11% JavaScript 0.27% Assembly 2.89%
kotlin-multiplatform sql sqldelight

sqldelight's Introduction

SQLDelight

See the project website for documentation and APIs

SQLDelight generates typesafe Kotlin APIs from your SQL statements. It verifies your schema, statements, and migrations at compile-time and provides IDE features like autocomplete and refactoring which make writing and maintaining SQL simple.

SQLDelight understands your existing SQL schema.

CREATE TABLE hockey_player (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  number INTEGER NOT NULL
);

It generates typesafe code for any labeled SQL statements.

intro.gif


SQLDelight supports a variety of dialects and platforms:

SQLite

MySQL (JVM)

PostgreSQL (JVM)

HSQL/H2 (JVM) (Experimental)

Snapshots

Snapshots of the development version (including the IDE plugin zip) are available in Sonatype's snapshots repository. Note that the coordinates are all app.cash.sqldelight instead of com.squareup.cash for the 2.0.0+ SNAPSHOTs.

Documentation pages for the latest snapshot version can be found here.

License

Copyright 2016 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

sqldelight's People

Contributors

3flex avatar aleckazakova avatar angusholder avatar aperfilyev avatar benasher44 avatar chippmann avatar dellisd avatar dependabot[bot] avatar egorand avatar eygraber avatar gabrielittner avatar goooler avatar griffio avatar hfhbd avatar jakewharton avatar jgulbronson avatar jrodbx avatar kevincianfarini avatar kpgalligan avatar mariusvolkhart avatar martinbonnin avatar oldergod avatar renovate-bot avatar renovate[bot] avatar runningcode avatar saket avatar shellderp avatar vanniktech avatar veyndan avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqldelight's Issues

Check that gradle plugin is installed from intellij plugin

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

Antlr dependency clashes with Databinding plugin.

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')
      }
    }
  }
}

Indent parsed incorrectly

Creates over-indented, mis-aligned lines after the first one.

  String FEMALES = ""
      + "SELECT *\n"
      + "    FROM users\n"
      + "   WHERE gender = 'FEMALE'";

Work with kotlin

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)

Switch key/value tables to using columns, not rows

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.

Views should be handled like tables

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

IllegalStateException in TableGenerator.kt:129 uncaught in plugin

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.

Solution for enums in where clauses

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)

Figure out what to do about migrations, if anything.

Working:

  • You can currently define inserts, updates, and deletes in a file and use them for migrations.

Annoying:

  • Table creation generates a bunch of nonsense you might not need if the table is deleted/altered by later migrations
  • Table creation is restricted to one per file

Missing:

  • Detection of breaking changes in the schema and warning about it
  • Generation of migrations automatically when you use refactoring tools on the create table statements?

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.

Generate type-safe query factories

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.

Method for update clauses in .sq files

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.

Support imports like Java in .sq files

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

Update to use released JavaPoet library.

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.

Script for generating expected files.

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.

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.