Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema API feedback #26

Closed
roll opened this issue Jul 6, 2017 · 1 comment
Closed

Schema API feedback #26

roll opened this issue Jul 6, 2017 · 1 comment

Comments

@roll
Copy link
Member

roll commented Jul 6, 2017

Overview

Based on this readme listing I'm adding feedback based on existent implementations and expected lib user competencies (as we target many almost non-tech users - publisher, data wranglers etc).

// validate and cast a row according to schema
$schema = new Schema('{"fields": ["name": "id", "type": "integer"]}');
$row = $schema->castRow(["id" => "1"]);
// raise exception if row fails validation
// returns row with all native values

// EditableSchema extends the Schema object with editing capabilities
$schema = new EditableSchema();
// set fields
$schema->fields([
    "id" => FieldsFactory::field((object)["name" => "id", "type" => "integer"])
]);
// remove field
$schema->removeField("age");
// edit primaryKey
$schema->primaryKey(["id"]);

// after every change - schema is validated and will raise Exception in case of validation errors
// finally, you can save the schema to a json file
$schema->save("my-schema.json");

Schema vs EditableSchema?

Consider as a {DATA WRANGLER} I create $schema = new Schema('{"fields": ["name": "id", "type": "integer"]}'); in REPL then just decide to edit it. So having a deal with two type of schemas could be not very user-friendly. In other languages editable objects don't have this separation.

Accept PHP array?

It's actual for all Table/Schema/Field APIs

For now schema descriptor should be either object, json-string or url-path:

Schema objects can be constructed using any of the following:

php object
string containing json
string containg value supported by file_get_contents 

Not sure do I understand PHP correctly here or not but why we can't write (using Field example):

FieldsFactory::field(["name" => "id", "type" => "integer"])

instead of casting to object first:

FieldsFactory::field((object)["name" => "id", "type" => "integer"])

I suppose it could be handled inside class (cast to object) but reduce usage errors.

OriHoch added a commit to OriHoch/tableschema-php that referenced this issue Jul 13, 2017
- remove EditableSchema, use the normal Schema instead
- allow to create field using json string or array
OriHoch added a commit that referenced this issue Jul 13, 2017
@OriHoch
Copy link
Collaborator

OriHoch commented Jul 13, 2017

fixed and merged to latest draft release v0.1.6

@OriHoch OriHoch closed this as completed Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants