Giter Site home page Giter Site logo

tader's People

Contributors

uklance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

doytsujin

tader's Issues

grater-core: Things to do

Extract logic from GraterModelImpl into GraterModelSource
Add duplicate table / column validation to GraterModelSourceImpl
Add getReferenceTable to ForeignKey
Create a GraterBuilder
Export Schema to file
Import Schema from file
Refactor TableRow into PartialEntity and Entity

Specify explicit columns for generated keys. Allow multiple columns to be auto generated by database

Currently, the generated key logic is a bit silly. It simply states to use Statement.RETURN_GENERATED_KEYS and can only return a single generated value. Ie it currently uses:

Connection.prepareStatement(String sql, int autoGeneratedKeys)

This should be improved and should use either

prepareStatement(String sql, int[] columnIndexes)

or

prepareStatement(String sql, String[] columnNames) 

Then we can populate more than one database generated value per insert

See
DefaultInsertHandler
JdbcEntityPersistence

Random thoughts

DB inserts

// hard code name and dob, generate the rest
def user1 = insert "user" [name:"user1", dob:"1/1/2000"]
def user2 = insert "user" [name:"user2", dob:"1/1/1980"]
def user3 = insert "user" [name:"user3", dob:"1/1/1980"]

// hard code name and user (foreign key) and generate the rest
def item1 = insert "item" [name:"item1", user:user1]

// hard code name and generate the rest. User (foreign key) will be generated
def item2 = insert "item" [name:"item2"]
def generatedUser = item2.user

// select and selectAll
def user1 = select "user" [name:"user1"]
List users = selectAll "user" [dob:"1/1/1980"]

// update and updateAll
user1.name = "user1a"
update user1

// delete and deleteAll
boolean deleted = delete "user" [name:"user1"]
int deleteCount = deleteAll "user" [dob:"1/1/1980"]

Brain dump

  • Allow string to x conversions
  • Multiple conversions per datatype via "date:1/1/2020" or "datetime:1/1/2020 10:22:55"
  • Configurable ValueGenerators
  • Parse schema from jdbc connection
  • Export schema to file for offline use
  • Allow decoration of schema
  • Allow [user:user1] and [userId:user1.userId]
  • Groovy dsl
  • Optional groovy dependency?
  • json / xml dsl? (phase2)
  • Configurable column_name to columnName
  • Configurable table_name to tableName

Classes

class Schema {
    Table[] tables;
}

class Table {
    String namespace;
    String name;
    PrimaryKey primaryKey;
    ForeignKey[] foreignKeys;
    Column[] columns;
}

class Column  {
    String name;
    Type type;
    boolean nullable;
    int scale;
    int precision;
}

class SchemaModel {
    Map<String Table> tables;
    Map<String, Map<String, Column>> columns;
    List<Table> tableCreationOrder;

    // this can as a suffix on generated values
    int getNextIncrement(Table table);

    // convert dsl value to db value
    ValueParser getValueParser(Table table, Column column, Object value, String prefix);
    ValueParser getDefaultValueParser(Type type, Object value, String prefix);

    // generate value not provided by user in dsl prior to insert
    ValueGenerator getValueGenerator(Table table, Column column);
    ValueGenerator getNullableValueGenerator(Table table, Column column);
    ValueGenerator getDefaultValueGenerator(Type type);
    ValueGenerator getDefaultNullableValueGenerator(Type type);

    // convert db value to value in dsl
    ValueConverter getValueConverter(Table table, Column column);
    ValueConverter getDefaultValueConverter(Type type);
}

interface Grater {
    Entity insert(String table, Map fields);
    <T extends Entity> insert(Class<T> type, Map fields);
    <T extends Entity> T insert(T fields);

    boolean delete(String table, Object pk);
    boolean delete(Entity entity);

    int deleteAll(String table, Map fields);
    int deleteAll(Entity fields);
}

interface Entity extends Serializable { ... }

interface ValueGenerator {
    Object generateValue(Table table, Column column, IncrementProvider incProvider);
}

interface ValueParser {
    Object parseValue(Table table, Column column, Object value);
}

interface ValueConverter {
    Object convert(Table table, Column column, ResultSet resultSet);
}

interface SchemaSource {
    Schema getSchema();
}

interface SchemaMerger {
    Schema merge(Schema[] schemas, MergeMode mode);
}

enum MergeMode { OVERRIDE, IGNORE }

interface SchemaExporter {
    void export(Schema schema);
}

class JdbcSchemaSource implements SchemaSource {
    String url, className, user, password, schema;
    String[] includes;
    String[] excludes;
}

class XMLSchemaSource implements SchemaSource { ... }

class JSONSchemaSource implements SchemaSource { ... }

class XMLSchemaExporter implements SchemaExporter { ... }

class JSONSchemaExporter implements SchemaExporter { ... }

class IdentityValueParser implements ValueParser { ... }

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.