<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Neyric.com &#187; Persevere</title>
	<atom:link href="http://neyric.com/tag/persevere/feed/" rel="self" type="application/rss+xml" />
	<link>http://neyric.com</link>
	<description>projects, programming, blogging...</description>
	<lastBuildDate>Sat, 29 Jan 2011 19:51:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>JSON Schema and inputEx</title>
		<link>http://neyric.com/2009/01/26/json-schema-and-inputex/</link>
		<comments>http://neyric.com/2009/01/26/json-schema-and-inputex/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 15:04:20 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Server-side javascript]]></category>
		<category><![CDATA[inputEx]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json-schema]]></category>
		<category><![CDATA[Persevere]]></category>

		<guid isPermaLink="false">http://javascript.neyric.com/blog/?p=92</guid>
		<description><![CDATA[Proposed by Kris Zyp, JSON Schema takes the good ideas from XML Schema. From http://json-schema.org/ : JSON Schema is a specification for a JSON-based format for defining the structure of JSON data. JSON Schema provides a contract for what JSON &#8230; <a href="http://neyric.com/2009/01/26/json-schema-and-inputex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Proposed by <a href="http://www.sitepen.com/blog/author/kzyp/">Kris Zyp</a>, JSON Schema takes the good ideas from XML Schema. From <a href="http://json-schema.org/">http://json-schema.org/</a> :</p>
<blockquote><p><em>JSON Schema is a specification for a JSON-based format for defining the structure of JSON data. JSON Schema provides a contract for what JSON data is required for a given application and how it can be modified, much like what XML Schema provides for XML. JSON Schema is intended to provide validation, documentation, and interaction control of JSON data.</em></p></blockquote>
<p>There are numerous similarities between inputEx and JSON Schema. If you are not convinced, here is an example of a JSON schema:</p>
<blockquote><p><code>{"description":"A person",<br />
"type":"object",</code></p>
<p><code> "properties": {<br />
"name": {"type":"string"},<br />
"born" : {</code></p>
<p><code> "type":["integer","string"],<br />
"minimum":1900,<em><br />
</em></code><code> "maximum":2010,<br />
</code></p>
<p><code> "format":"date-time", <em><br />
</em> "optional":true<br />
</code><code> },<br />
"gender" : {"type":"string",<br />
"options":[</code></p>
<p><code> {"value:"male","label":"Guy"},</code></p>
<p><code> {"value":"female","label":"Gal"}]},</code><code><br />
"address" : {"type":"object"</code><code>,<br />
"properties":{</code></p>
<p><code> "street":{"type":"string"},<br />
"city":{"type":"string"},<br />
"state":{"type":"string"}<br />
}<br />
}<br />
</code></p>
<p><code> }<code><br />
</code>}</code></p></blockquote>
<p>inputEx users should be comfortable writing a form for this schema :</p>
<blockquote><p>{</p>
<p>type: &#8220;group&#8221;,</p>
<p>fields: [</p>
<p>{type: "string", inputParams: {name: "name", required: true}},</p>
<p>{type: "date", inputParams: {name: "born"} },</p>
<p>{type: "select", inputParams: {name: "gender", selectOptions:["Guy", "Gal"], selectValues: ["male", "female"]}},</p>
<p>{type: &#8220;group&#8221;, inputParams: {</p>
<p>name:&#8221;address&#8221;,</p>
<p>fields: [</p>
<p>{type: "string", inputParams: {name: "street"}},</p>
<p>{type: "string", inputParams: {name: "city"}},</p>
<p>{type: "string", inputParams: {name: "state"}}</p>
<p>]    }  }  ] }</p></blockquote>
<p>The main difference is that the<strong> JSON schema ontology is data-centric, wheras the inputEx JSON schema ontology is form-centric</strong>, but as you can see, they are very similar.</p>
<p>Another similarity is the self-descriptive ability of JSON Schema and inputEx.<a href="http://code.google.com/p/jsonschema/downloads/detail?name=schemaForSchema.json&amp;can752&amp;q="> JSON Schema has its own schema</a>, a schema for itself. inputEx has the same kind of self reference: the TypeField contains forms to describe the options of each field (you can see this at the end of <a href="http://javascript.neyric.com/inputex/doc/js_docs_out/TypeField.js.html">TypeField.js</a>). This self-referencing property has very nice implications: it gives the opportunity to create <strong>a form to build forms</strong>, and that&#8217;s exactly what the <a href="http://javascript.neyric.com/inputex/inputExBuilder/inputExBuilder.html">inputEx Builder</a> is: a form which outputs inputEx JSON.</p>
<p><strong>inputEx implementation of JSON Schema</strong></p>
<p>In version 0.2.0, I added a (very) light implementation of a JSON Schema to inputEx JSON. Hopefully, Brad Clements saw the advantages of having automatic form generation from JSON schemas and took the prototype one (big) step forward by implementing <a href="http://www.json.com/2007/10/19/json-referencing-proposal-and-library/">JSON referencing</a>. We are now able to create atomic schemas and combine them in nested schemas.</p>
<p>At the current state, inputEx doesn&#8217;t implement all the validation that can be described in JSON Schema, but we are on the way. On the other hand, inputEx has many options concerning the form interface, that are not necessary in JSON Schema, which focuses on data validation. Brad suggested an extension to JSON Schema by adding an &#8220;_inputex&#8221; property to type definition. It allows to set the additionnal interface options for inputEx within the schema.</p>
<p>Both of these features are demonstrated in <a href="http://javascript.neyric.com/inputex/examples/json-schema2.html">this example</a> which is built from <a href="http://javascript.neyric.com/inputex/examples/base-schema.js">this schema</a> (JSON schema with inputEx extension).</p>
<p>The last feature that we&#8217;re missing is the extending capability (&#8220;extends&#8221;:{&#8220;$ref&#8221;:&#8221;person&#8221;}), but the implementation should be pretty straightforward.</p>
<p><strong>Round-trip: defining JSON-Schema through forms, and </strong><strong>Persevere backend</strong></p>
<p>Up to now, we focused on converting JSON schemas to inputEx forms, but the other way is perfectly conceivable ! Leveraging the inputEx Builder, we would have a nice interface to <strong>build JSON schemas and associated forms </strong><strong>at the same time</strong>. Combined<strong> </strong>with the <a href="http://www.persvr.org/">Persevere</a> framework backend, we could provide a very nice administration interface, that let you edit models through the inputEx Builder, then edit the data through the generated inputEx forms. You could argue that some fields should not be visible in forms, but if you take a closer look at inputEx fields, two of them are perfect for this case: the <a href="http://javascript.neyric.com/inputex/examples/hidden_field.html">HiddenField</a>, which is not visible at all, or the <a href="http://javascript.neyric.com/inputex/examples/uneditable_field.html">UneditableField</a> which lets you use a custom rendering method for an uneditable field.</p>
<p>I think this might end up in a more effective interface than the <a href="http://www.persvr.org/explorer.html">current Persevere database explorer</a> because it creates the form interfaces at the same time, and make them reusable within your application.</p>
<p>A last idea, we could provide json-schemas for defining method parameters. inputEx could then automatically generate forms to call these methods (through JSON-RPC or locally).</p>
<p>Of course, if you&#8217;re interested in the following developments, we urge you to contact us <a href="http://groups.google.com/group/inputex/">through the forum</a>.</p>
<p>Have fun !</p>
<div class="shr-publisher-143"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2009/01/26/json-schema-and-inputex/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to setup a mysql data source for Persevere</title>
		<link>http://neyric.com/2008/07/31/how-to-setup-a-mysql-data-source-for-persevere/</link>
		<comments>http://neyric.com/2008/07/31/how-to-setup-a-mysql-data-source-for-persevere/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 14:29:36 +0000</pubDate>
		<dc:creator>neyric</dc:creator>
				<category><![CDATA[Server-side javascript]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Persevere]]></category>
		<category><![CDATA[serverside]]></category>

		<guid isPermaLink="false">http://javascript.neyric.com/blog/?p=75</guid>
		<description><![CDATA[If you don&#8217;t know Persevere yet, check out its impressive list of features (JSONPath/JSON-RPC/Comet support, etc&#8230;). Here is a short tutorial to expose your MySQL tables through the persevere JSON REST interface. Download persevere and unzip it. Download the JDBC &#8230; <a href="http://neyric.com/2008/07/31/how-to-setup-a-mysql-data-source-for-persevere/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://persevere.sitepen.com/res/persevere.png" alt="Persevere logo" width="410" height="57" /></p>
<p>If you don&#8217;t know <a href="http://persevere.sitepen.com/">Persevere</a> yet, check out its impressive list of features (JSONPath/JSON-RPC/Comet support, etc&#8230;).</p>
<p>Here is a short tutorial to expose your MySQL tables through the persevere JSON REST interface.</p>
<ol>
<li>Download <a href="http://code.google.com/p/persevere-framework/">persevere</a> and unzip it.</li>
<li>Download the <a href="http://dev.mysql.com/downloads/connector/j/5.1.html">JDBC driver for MySQL</a> and put the jar file into the &#8220;persevere/lib&#8221; folder.</li>
<li>Create a new file in &#8220;persevere/WEB-INF/config&#8221; named &#8220;myDatabase.json&#8221;</li>
<li>We will now configure the data source: (replace &#8220;myDatabase&#8221; and &#8220;myTable&#8221; by your database and table names.)<code><br />
({<br />
"id":"myDatabase.json",<br />
"sources": [<br />
{<br />
"name":"myTable",<br />
"sourceClass":"org.persvr.datasource.DatabaseTableDataSource",<br />
"driver":"com.mysql.jdbc.Driver",<br />
"connection":<br />
"jdbc:mysql://localhost/myDatabase?user=myDbUser&amp;pass=",<br />
"table":"myTable",<br />
"idColumn":"id",<br />
"dataColumns": [<br />
"lastname",<br />
"firstname",<br />
...and so on with your table columns<br />
],<br />
"schema":{<br />
"data":{"$ref":"../</code><code>myTable</code><code>/"}<br />
}<br />
}<br />
]<br />
}</code>Don&#8217;t forget to change your database user name and password !</li>
<li>run persevere (&#8220;java -jar start.jar&#8221;) and visit the following pages:
<ul>
<li>http://localhost:8080/myTable</li>
<li>http://localhost:8080/myTable/</li>
<li>http://localhost:8080/myTable/1</li>
</ul>
</li>
</ol>
<p>What to do next ?</p>
<ul>
<li>Add other tables: &#8220;sources&#8221; is an array !</li>
<li>Use UTF8:  Adds the following at the end of  the connection string: <code>&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;mysqlEncoding=utf8</code></li>
<li>Add methods to the class or to its prototype (take a look at WEB-INF/config/examples.json)</li>
<li>Write a script to auto-generate the config file from a database structure (and post it on the <a href="http://groups.google.com/group/persevere-framework">persevere forum</a>)</li>
<li>Read the <a href="http://persevere.sitepen.com/persevere-client-readme.html">Persevere Javascript Client Documentation</a> and start coding applications !</li>
</ul>
<p>Have fun !</p>
<div class="shr-publisher-138"></div>]]></content:encoded>
			<wfw:commentRss>http://neyric.com/2008/07/31/how-to-setup-a-mysql-data-source-for-persevere/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

