{"id":13578340,"url":"https://github.com/ignoreintuition/jSchema","last_synced_at":"2025-04-05T16:32:20.224Z","repository":{"id":83767847,"uuid":"107207208","full_name":"ignoreintuition/jSchema","owner":"ignoreintuition","description":"A simple, easy to use data modeling framework for JavaScript","archived":false,"fork":false,"pushed_at":"2018-04-19T03:04:22.000Z","size":2386,"stargazers_count":266,"open_issues_count":5,"forks_count":21,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-05T15:50:02.174Z","etag":null,"topics":["data","data-modeling","data-structures","data-visualization","dataset","drop","filter","group","groupby","hacktoberfest","javascript","javascript-library","multiple-datasets","orderby","sort"],"latest_commit_sha":null,"homepage":"http://resurgencewebdesign.com/jschema/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ignoreintuition.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-10-17T02:22:33.000Z","updated_at":"2024-05-01T18:34:58.000Z","dependencies_parsed_at":"2023-03-12T19:42:40.844Z","dependency_job_id":null,"html_url":"https://github.com/ignoreintuition/jSchema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignoreintuition%2FjSchema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignoreintuition%2FjSchema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignoreintuition%2FjSchema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ignoreintuition%2FjSchema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ignoreintuition","download_url":"https://codeload.github.com/ignoreintuition/jSchema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247366616,"owners_count":20927547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","data-modeling","data-structures","data-visualization","dataset","drop","filter","group","groupby","hacktoberfest","javascript","javascript-library","multiple-datasets","orderby","sort"],"created_at":"2024-08-01T15:01:29.618Z","updated_at":"2025-04-05T16:32:15.365Z","avatar_url":"https://github.com/ignoreintuition.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jSchema\n\n![logo](https://user-images.githubusercontent.com/5210420/32085476-48b25564-ba9d-11e7-8a6e-9e2df9cd5ed5.png)\n\n## Data Modeling in JavaScript\njSchema is a framework for modeling data in JavaScript.  By using fundamental data modeling principles you are able to pull multiple datasets into a common schema, define relationships, aggregate, join, and subset datasets to make data easier to work with in the browser.\n\n![entity relationship diagram - new page 1](https://user-images.githubusercontent.com/5210420/32084304-50e6bdbc-ba96-11e7-92b8-cfab13866fe0.png)\n\njSchema is going to create an object called `jSchema`.  This object is a metadata representation of all your datasets containing the table names, column names, and keys that define sets.  The data itself is stored in a closure within the object and is retrieved via a getter function.  Joining data, aggregating data, and filtering data will create a new dataset in your WORK namespace that will persist on the page until either you delete the table or you run a cleanUp method.  By default jSchema will be case sensitive.  This can be overwritten with:\n\n```JavaScript\nvar s = new jSchema({\n  \"caseSensitive\": false\n});\n```\n\n## Demo\n\nA complete working demo of how to load tables, join tables, and aggregate tables can be found in the repository in the demo folder.  A live demo can be found on the libraries homepage: [live demo](http://resurgencewebdesign.com/refugee/)\n\n\n## How to Use\n\n### NPM\nIf you use npm, `npm install jschema`.\n\n### requirejs\njschema.js uses requirejs to modularly load the library and is included in the package.json.  requirejs can be moved to the lib directory of your project and included as:\n\n```html\n\u003cscript data-main=\"main\" src=\"lib/require.js\"\u003e\u003c/script\u003e\u003c/body\u003e\n```\nwhere main is main.js.  You can then add jSchema to your application as such (in this case main.js):\n\n```JavaScript\nrequirejs(['lib/jschema'], function(jSchema){\n  var s = new jSchema;\n\n  s.add([{a:1, b:2}])\n  s.add([{b:2, c:3}], {name:\"named_table\", primaryKey:\"b\"})\n});\n```\n\nOr load data from external sources:\n\n```JavaScript\nfetch(\"education.json\")\n  .then(response =\u003e response.json())\n  .then(json =\u003e s.add(json, {name:\"education\", primaryKey:\"Age_Group\"}))\n  .then(fetch(\"gender.json\")\n    .then(response =\u003e response.json())\n    .then(json =\u003e s.add(json, {name:\"gender\", primaryKey:\"Age_Group\"}))\n);\n```\n### JOIN\nMultiple datasets that have primary / foreign key relationships can be joined as such:\n\n```JavaScript\ns.join(\"EDUCATION\", \"GENDER\", {name: \"joinTable\"})\n```\n\n### DROP\nYou can drop tables that are no longer needed in the schema with the drop method:\n\n```JavaScript\ns.drop(\"GENDER\")\n```\n\n### SORT\nIf you want to sort a dataset by an attribute use the orderBy method:\n\n```JavaScript\ns.orderBy(\"GENDER\", {\n  clause: \"Count\",\n  order: \"asc\",\n  name: \"sortBy\"\n})\n```\n\n### GROUP BY\nTo Group by you need to provide the dataset name, the name of the dimension to group by, and the metrics you wish to aggregate:\n\n```JavaScript\ns.groupBy(\"GENDER\", {\n  dim: \"Gender\",\n  metric: \"Count\",\n  name: \"groupBy\",\n  method: \"sum\", // supported methods are sum, count, average, min, max\n  percision: 2, // default is 2\n  dimName: \"GenderPK\" // use if you need to rename the dimension\n})\n```\nOutput:\n```JSON [\n  {\n    \"dim\": \"Male\",\n    \"val\": 37575\n  },\n  {\n    \"dim\": \"Female\",\n    \"val\": 44074\n  }\n]\n```\n\n### FILTER\nTo filter a dataset you can call the filter method and pass three or more arguments.  First argument is always the table name.  The second and third are the field to filter by, and the value to filter it on.  Additional pairs can be included as fourth, fifth parameters and so on.  A filtered dataset will be created in the WORK namespace.\n\n```JavaScript\ns.filter('GENDER', 'Gender', 'Female')\n```\n\n### UPDATE\nIf a new version of the dataset is made available you can update the existing table in the schema by running the update method:\n\n```JavaScript\ns.update(\"GENDER\", data);\n```\n\n### INSERT\nInserting data into a table will add additional rows to your table.  This will not affect any of the existing data in the table.  A single row can be passed as an object or an array of objects can be passed.  Column names need to match in order for the new data to appear when retrieved.\n\n```JavaScript\ns.insert(\"TABLE0\", {\n  \"gender\": \"Female\",\n  \"age_group\": \"16-24\",\n  \"count\": 10\n});\n```\n\n### REMOVE COLUMNS\nIf you want to completely remove a column use removeCol to create a clone of the table with the column removed.  Pass the dataset as the first argument and the attributes as the second argument.  Attributes are `col` for the column to be removed, and `name` for the name of the table to clone the table to.  Name is optional and if it is not used it will copy the data to the WORK namespace.\n\n```JavaScript\ns.removeCol(\"COMPLETE\", {\n  \"col\": \"REFUGEES_BY_DEST.STATE\",\n  \"name\": \"REFUGEES_CLEAN\"\n});\n```\n\n### ADD COLUMNS\nIn order to add a new column to a dataset you need to call the addCol method.  This will take an expression (two columns and an arithmetic operator) and combine them into a new field.  The function will create a new dataset with the name passed in the attribute `name` , and will return the schema object.  If `name` is not provided it will create a dataset in the WORK namespace.\n\n```JavaScript\ns.addCol(\"REFUGEES_CLEAN\", {\n  \"name\": \"REFUGEES_ARITHMETIC\",\n  \"expression\": \"REFUGEES_BY_DEST.VAL / POPULATION.POP_EST_2014\",\n  \"colName\": \"AVG_POP_DEST\"\n})\n```\n\nBy default all temporary datasets (joins, group by, order by) added to the schema will be prefixed with the namespace WORK. (e.g. joining two tables NAMES and LOCATIONS will result in a table added to the schema called WORK.NAMES_LOCATIONS).  Calling the cleanUp method will remove all datasets added to the WORK namespace\n\n```JavaScript\ns.cleanUp();\n```\n\n# Testing\nTo run mocha test scripts from the terminal type:\n\n```JavaScript\nnpm install\nnpm run test\n```\n\n# Contact\nQuestions, comments, feature requests, etc are always welcome.  I am [@ignoreintuition](https://twitter.com/IgnoreIntuition) on Twitter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignoreintuition%2FjSchema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fignoreintuition%2FjSchema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fignoreintuition%2FjSchema/lists"}