diff --git a/api/src/Server.hx b/api/src/Server.hx index 92f3b4b..deb6d49 100644 --- a/api/src/Server.hx +++ b/api/src/Server.hx @@ -1,9 +1,10 @@ -import html.Document; +import html.WebDocument; import tink.http.containers.*; import tink.http.Response; import tink.web.routing.*; import haxe.Json; - +import tink.sql.drivers.Sqlite; +import db.Db; typedef T_project = { @@ -29,16 +30,40 @@ class Server { } class Root { - public function new() {} - - + public function new() {} @:get('/') @:produces('text/html') public function root(){ - return Document.render(); + //return "yeet"; + return WebDocument.render(); + } + + @:get('/test') + @:produces('text/html') + @async + public function create(){ + //return "yeet"; + var yeet = "yote"; + var driver = new tink.sql.drivers.Sqlite(); + @await var db = new Db('daba2', driver); + @await var one = db.User.create(); + @await var two = db.User.insertOne({ + id: cast null, + name: 'Alice', + email: 'alice@example.com', + password: 'jew' + }); + @await var three = db.User.select({name: User.name, email: User.email}).where(User.email == 'alice@example.com').first().next(function(row) { + trace(row.name);return ""; + }); + // trace(@await one); + // trace(@await two); + trace(@await three); + return '$yeet'; } @:sub('/projects') + @:produces('application/json') public function projects() return new Projects(); @@ -49,6 +74,7 @@ class Root { var strout:String = tink.Json.stringify(greeting); return strout; } + } class Projects { diff --git a/api/src/db/Connection.hx b/api/src/db/Connection.hx new file mode 100644 index 0000000..bd6ded0 --- /dev/null +++ b/api/src/db/Connection.hx @@ -0,0 +1,10 @@ +package db; + +import tink.sql.drivers.sys.Sqlite; +import tink.sql.drivers.MySql; +import db.Db; + +class Connection{ + private static var driver = new tink.sql.drivers.Sqlite(); + public static var db = new Db('daba', driver); +} \ No newline at end of file diff --git a/api/src/db/Db.hx b/api/src/db/Db.hx new file mode 100644 index 0000000..078d1b4 --- /dev/null +++ b/api/src/db/Db.hx @@ -0,0 +1,17 @@ +package db; + +// import tink.sql.drivers.Sqlite; +//import tink.sql.Database; +import tink.sql.Types; +import model.User; + +// import db.Models.User; + + + +typedef Db = tink.sql.Database; +@:tables(User) +interface Def extends tink.sql.DatabaseDefinition { + //@:procedure var func:Int->{x:Int, point:tink.s2d.Point}; + //@:table('user') var UserAlias:User; +} \ No newline at end of file diff --git a/api/src/db/Models.hx b/api/src/db/Models.hx new file mode 100644 index 0000000..da630aa --- /dev/null +++ b/api/src/db/Models.hx @@ -0,0 +1,11 @@ +package db; + +import tink.sql.Types; + + +typedef User = { + @:autoIncrement @:primary public var id(default, null):Id; + var name:VarChar<255>; + @:unique var email:VarChar<255>; + var password:VarChar<255>; +} \ No newline at end of file diff --git a/api/src/html/WebDocument.hx b/api/src/html/WebDocument.hx index d8e0692..ef3dee6 100644 --- a/api/src/html/WebDocument.hx +++ b/api/src/html/WebDocument.hx @@ -8,6 +8,7 @@ import tink.web.routing.Router; class WebDocument{ public static function render():String { + var docroot:Tag = new Tag("html"); var head:Tag = new Tag("head"); var body:Tag = new Tag("body"); diff --git a/api/src/model/User.hx b/api/src/model/User.hx new file mode 100644 index 0000000..87faee5 --- /dev/null +++ b/api/src/model/User.hx @@ -0,0 +1,11 @@ +package model; + +import tink.sql.Types; + + +typedef User = { + @:autoIncrement @:primary public var id(default, null):Id; + public var name:VarChar<50>; + public var email:VarChar<50>; + public var password:VarChar<50>; +} \ No newline at end of file diff --git a/api/src/model/cctweaked/HTurtle.hx b/api/src/model/cctweaked/HTurtle.hx new file mode 100644 index 0000000..6148e03 --- /dev/null +++ b/api/src/model/cctweaked/HTurtle.hx @@ -0,0 +1,9 @@ +package model.cctweaked; + +import tink.sql.Types; + +typedef HTurtle = { + @:autoIncrement @:primary public var id(default, null):Id; + public var name:VarChar<50>; + public var password:VarChar<50>; +} \ No newline at end of file