<commit_before>#if php
import php.Lib;
import php.Web;
#elseif neko
import neko.Lib;
import neko.Web;
#end

import haxe.web.Dispatch;
import sys.db.Types;

class Index {

	#if php
	static var platform = "PHP";
	#elseif neko
	static var platform = "neko";
	#end

	static var dbconn : Null<sys.db.Connection> = null;

	public static function main() {
		try {
			Dispatch.run(Web.getURI(), Web.getParams(), Index);
		} catch (de : DispatchError) {
			switch (de) {
				case DENotFound(part):
					Lib.print("No such page: " + part);
				case DEInvalidValue:
					Lib.print("Invalid value");
				case DEMissingParam(p):
					Lib.print("Missing parameter: " + p);
				case DETooManyValues:
					Lib.print("Too many values");
				default:
					Lib.print("Weird error");
			}
		}
	}

	private static function initDb() : Void {
		if (dbconn == null) {
			sys.db.Manager.initialize();
			dbconn = sys.db.Sqlite.open("test.sqlite");
			sys.db.Manager.cnx = dbconn;
		}
		if (!sys.db.TableCreate.exists(TestTable.manager)) {
			sys.db.TableCreate.create(TestTable.manager);
		}
	}

	public static function doCool(args : { x : Int, v : String } ) : Void {
		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({ title: "Cool page " + platform,
								 body: "" + args.x + " " + args.v });
		Lib.print(output);
	}

	public static function doGet() : Void {
		initDb();
		var results = TestTable.manager.search(true);
		var table = "<ul>";
		for (r in results) {
			table += "<li>";
			table += r.name + ", " + r.age;
			table += "</li>";
		}
		table += "</ul>";

		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({
			title: "DB contents " + platform,
			body: "" + table });
		Lib.print(output);
	}

	public static function doInsert(args : {
		name : String, age : Int }) : Void {
		initDb();
		var entry = new TestTable();
		entry.name = args.name;
		entry.age = args.age;
		entry.insert();

		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({
			title: "Insert " + entry.name + " " + platform,
			body: "inserted " + entry.name + ", " + entry.age + " years old" });
		Lib.print(output);
	}

}

class TestTable extends sys.db.Object {
	public var id : SId;
	public var name : SString<32>;<commit_msg>added a couple web references<commit_after>#if php
import php.Lib;
import php.Web;
#elseif neko
import neko.Lib;
import neko.Web;
#end

import haxe.web.Dispatch;
import sys.db.Types;

class Index {

	#if php
	static var platform = "PHP";
	#elseif neko
	static var platform = "neko";
	#end

	static var dbconn : Null<sys.db.Connection> = null;

	public static function main() {
		try {
			// see http://old.haxe.org/manual/dispatch
			Dispatch.run(Web.getURI(), Web.getParams(), Index);
		} catch (de : DispatchError) {
			switch (de) {
				case DENotFound(part):
					Lib.print("No such page: " + part);
				case DEInvalidValue:
					Lib.print("Invalid value");
				case DEMissingParam(p):
					Lib.print("Missing parameter: " + p);
				case DETooManyValues:
					Lib.print("Too many values");
				default:
					Lib.print("Weird error");
			}
		}
	}

	private static function initDb() : Void {
		// see http://old.haxe.org/manual/spod
		if (dbconn == null) {
			sys.db.Manager.initialize();
			dbconn = sys.db.Sqlite.open("test.sqlite");
			sys.db.Manager.cnx = dbconn;
		}
		if (!sys.db.TableCreate.exists(TestTable.manager)) {
			sys.db.TableCreate.create(TestTable.manager);
		}
	}

	public static function doCool(args : { x : Int, v : String } ) : Void {
		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({ title: "Cool page " + platform,
								 body: "" + args.x + " " + args.v });
		Lib.print(output);
	}

	public static function doGet() : Void {
		initDb();
		var results = TestTable.manager.search(true);
		var table = "<ul>";
		for (r in results) {
			table += "<li>";
			table += r.name + ", " + r.age;
			table += "</li>";
		}
		table += "</ul>";

		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({
			title: "DB contents " + platform,
			body: "" + table });
		Lib.print(output);
	}

	public static function doInsert(args : {
		name : String, age : Int }) : Void {
		initDb();
		var entry = new TestTable();
		entry.name = args.name;
		entry.age = args.age;
		entry.insert();

		var str = haxe.Resource.getString("testpage");
		var t = new haxe.Template(str);
		var output = t.execute({
			title: "Insert " + entry.name + " " + platform,
			body: "inserted " + entry.name + ", " + entry.age + " years old" });
		Lib.print(output);
	}

}

// see http://old.haxe.org/manual/spod
class TestTable extends sys.db.Object {
	public var id : SId;
	public var name : SString<32>;
{'fraction_non_alphanumeric': 0.1648148148148148, 'fraction_numerical': 0.0008230452674897119, 'mean_word_length': 3.0951979780960404, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5765218', 'n_tokens_mistral': 1957, 'n_tokens_neox': 1696, 'n_words': 429}