various changes

This commit is contained in:
Hion-V 2022-06-04 09:27:49 +02:00
parent 0409c28e4c
commit 2d1eb509f1
7 changed files with 91 additions and 6 deletions

View File

@ -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 {

10
api/src/db/Connection.hx Normal file
View File

@ -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);
}

17
api/src/db/Db.hx Normal file
View File

@ -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<Def>;
@:tables(User)
interface Def extends tink.sql.DatabaseDefinition {
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
//@:table('user') var UserAlias:User;
}

11
api/src/db/Models.hx Normal file
View File

@ -0,0 +1,11 @@
package db;
import tink.sql.Types;
typedef User = {
@:autoIncrement @:primary public var id(default, null):Id<User>;
var name:VarChar<255>;
@:unique var email:VarChar<255>;
var password:VarChar<255>;
}

View File

@ -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");

11
api/src/model/User.hx Normal file
View File

@ -0,0 +1,11 @@
package model;
import tink.sql.Types;
typedef User = {
@:autoIncrement @:primary public var id(default, null):Id<User>;
public var name:VarChar<50>;
public var email:VarChar<50>;
public var password:VarChar<50>;
}

View File

@ -0,0 +1,9 @@
package model.cctweaked;
import tink.sql.Types;
typedef HTurtle = {
@:autoIncrement @:primary public var id(default, null):Id<HTurtle>;
public var name:VarChar<50>;
public var password:VarChar<50>;
}