Compare commits
4 Commits
edc1ea081f
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 843f779010 | |||
| 78fd88654d | |||
| 853f5eba26 | |||
| 6962885582 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,3 +2,5 @@ api2/
|
|||||||
**/build/
|
**/build/
|
||||||
out.js
|
out.js
|
||||||
api/node_modules/
|
api/node_modules/
|
||||||
|
**/*.sqlite
|
||||||
|
**/.vscode/
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
-lib tink_http
|
-lib tink_http
|
||||||
-lib tink_web
|
-lib tink_web
|
||||||
|
-lib tink_core
|
||||||
#-lib tink_hxx
|
#-lib tink_hxx
|
||||||
-lib tink_json
|
-lib tink_json
|
||||||
-lib tink_sql
|
-lib tink_sql
|
||||||
-lib hxnodejs
|
-lib hxnodejs
|
||||||
|
# -D await_catch_none
|
||||||
-cp src
|
-cp src
|
||||||
--main Server
|
--main Server
|
||||||
-js build/out.js
|
-js build/out.js
|
||||||
|
|||||||
1187
api/package-lock.json
generated
1187
api/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
|
"sqlite": "^4.1.2",
|
||||||
"sqlite3": "^5.0.11"
|
"sqlite3": "^5.0.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,20 +4,30 @@ import tink.http.Response;
|
|||||||
import tink.web.routing.*;
|
import tink.web.routing.*;
|
||||||
import tink.sql.drivers.Sqlite;
|
import tink.sql.drivers.Sqlite;
|
||||||
import db.Db;
|
import db.Db;
|
||||||
|
import haxe.Json;
|
||||||
|
|
||||||
import model.MUser;
|
import model.MUser;
|
||||||
|
|
||||||
import controller.IDGen;
|
import controller.IDGen;
|
||||||
import controller.User;
|
import controller.User;
|
||||||
|
|
||||||
|
typedef T_project = {
|
||||||
|
name : String,
|
||||||
|
description : String,
|
||||||
|
url : String
|
||||||
|
}
|
||||||
|
typedef T_projects = {
|
||||||
|
version : Int,
|
||||||
|
projects : Array<T_project>
|
||||||
|
}
|
||||||
|
|
||||||
class Server {
|
class Server {
|
||||||
|
@await public static var db:Db;
|
||||||
static function main() {
|
static function main() {
|
||||||
var container = new NodeContainer(8080);
|
var container = new NodeContainer(8080);
|
||||||
//var container = PhpContainer.inst; //use PhpContainer instead of NodeContainer when targeting PHP
|
//var container = PhpContainer.inst; //use PhpContainer instead of NodeContainer when targeting PHP
|
||||||
var router = new Router<Root>(new Root());
|
var router = new Router<Root>(new Root());
|
||||||
|
Db.createTables();
|
||||||
container.run(function(req) {
|
container.run(function(req) {
|
||||||
return router.route(Context.ofRequest(req))
|
return router.route(Context.ofRequest(req))
|
||||||
.recover(OutgoingResponse.reportError);
|
.recover(OutgoingResponse.reportError);
|
||||||
@@ -82,3 +92,29 @@ class Root {
|
|||||||
return new IDGen();
|
return new IDGen();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Projects {
|
||||||
|
public function new() {}
|
||||||
|
|
||||||
|
public var path:String = "./res/json/projects.json";
|
||||||
|
|
||||||
|
@:get('/')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function projects(){
|
||||||
|
var json:String = Utils.getJson(path);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
@:get('/project/by_name/$name')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function project(name:String){
|
||||||
|
var json:String = Utils.getJson(path);
|
||||||
|
var _projects:T_projects = Json.parse(json);
|
||||||
|
json = "{}";
|
||||||
|
for(_project in _projects.projects){
|
||||||
|
if(_project.name == name){
|
||||||
|
json = tink.Json.stringify(_project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,14 +3,18 @@ package controller;
|
|||||||
import haxe.Json;
|
import haxe.Json;
|
||||||
import Utils;
|
import Utils;
|
||||||
import db.Db;
|
import db.Db;
|
||||||
|
import tink.sql.Fields;
|
||||||
import model.MUser;
|
import model.MUser;
|
||||||
|
import tink.core.*;
|
||||||
|
|
||||||
|
using Lambda;
|
||||||
|
using tink.CoreApi;
|
||||||
|
|
||||||
|
|
||||||
class User{
|
class User{
|
||||||
|
private static var driver = new tink.sql.drivers.Sqlite();
|
||||||
|
@await private static var db:Db = new Db('db.sqlite', driver);
|
||||||
public function new() {}
|
public function new() {}
|
||||||
public static var driver = new tink.sql.drivers.Sqlite();
|
|
||||||
@await public static var db = new Db('db.sqlite', driver);
|
|
||||||
|
|
||||||
|
|
||||||
@:get('/')
|
@:get('/')
|
||||||
@:produces('text/plain')
|
@:produces('text/plain')
|
||||||
@@ -19,25 +23,88 @@ class User{
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:get('/registerDummyUser')
|
|
||||||
@:produces('text/plain')
|
|
||||||
public function registerdummyuser(){
|
|
||||||
|
|
||||||
//@await var db = new Db('daba2', driver);
|
// @await public function createUserTable():Promise<Bool>
|
||||||
db.MUser.create().next(function(){
|
// {
|
||||||
db.MUser.insertOne({
|
// // @await var status:Promise<Bool> =;
|
||||||
|
// @await var op = db.MUser.create();
|
||||||
|
// op.handle(function(outcome){
|
||||||
|
// switch outcome {
|
||||||
|
// case Success(data):
|
||||||
|
// trace(data);
|
||||||
|
// return data;
|
||||||
|
// case Failure(e):
|
||||||
|
// trace("failure: "+e);
|
||||||
|
// return e.data;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
@await public function createUserTable():Promise<Bool>
|
||||||
|
{
|
||||||
|
// @await var status:Promise<Bool> =;
|
||||||
|
@await var op = db.MUser.create();
|
||||||
|
op.handle(function(outcome){
|
||||||
|
switch outcome {
|
||||||
|
case Success(data):
|
||||||
|
trace(data);
|
||||||
|
//return data;
|
||||||
|
case Failure(e):
|
||||||
|
trace("failure: "+e);
|
||||||
|
//return e.data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@:get('/registerDummyUser')
|
||||||
|
@:produces('application/json')
|
||||||
|
public function registerdummyuser(){
|
||||||
|
//@await var db = new Db('db.sqlite', driver);
|
||||||
|
// var failed:tink.core.Next<tink.sql.Id<model.MUser>> = null
|
||||||
|
return createUserTable().next(function(_){
|
||||||
|
return db.MUser.insertOne({
|
||||||
id: cast null,
|
id: cast null,
|
||||||
name: 'Alice',
|
name: 'Alice',
|
||||||
email: 'alice@example.com',
|
email: 'alice@example.com',
|
||||||
password: 'jew'
|
password: 'jew'
|
||||||
}).next(function(){
|
});
|
||||||
db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
}).next(function(_){
|
||||||
trace(row.name);
|
return db.MUser.select({id: MUser.id, name: MUser.name, email: MUser.email, password: MUser.password}).where(MUser.id == _).first().next(function(row) {
|
||||||
// return "$row";
|
return row;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return "success";
|
// @await var createTable = db.MUser.create().handle(function(outcome) {
|
||||||
|
// @await var insert = db.MUser.insertOne({
|
||||||
|
// id: cast null,
|
||||||
|
// name: 'Alice',
|
||||||
|
// email: 'alice@example.com',
|
||||||
|
// password: 'jew'
|
||||||
|
// }).next(function(_){
|
||||||
|
// trace(_);
|
||||||
|
// trace("wat");
|
||||||
|
// return { name: "klaas" };
|
||||||
|
// });
|
||||||
|
// trace(@await result);
|
||||||
|
// switch outcome {
|
||||||
|
// case Success(data):
|
||||||
|
// trace(data);
|
||||||
|
// return data;
|
||||||
|
// case Failure(e):
|
||||||
|
// trace("failure: "+e);
|
||||||
|
// return e.data;
|
||||||
|
// }
|
||||||
|
// return outcome;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// trace(@await result);
|
||||||
|
// trace("kak");
|
||||||
|
// trace(result.status);
|
||||||
|
//return result;
|
||||||
|
// return {name: "Kees"};
|
||||||
|
//@await return result.next.;
|
||||||
|
//@await return result;
|
||||||
// @await var three = ;
|
// @await var three = ;
|
||||||
// trace(@await one);
|
// trace(@await one);
|
||||||
// trace(@await two);
|
// trace(@await two);
|
||||||
@@ -50,8 +117,6 @@ class User{
|
|||||||
@:get('/fetchalice')
|
@:get('/fetchalice')
|
||||||
@:produces('application/json')
|
@:produces('application/json')
|
||||||
public function fetchalice(){
|
public function fetchalice(){
|
||||||
var driver = new tink.sql.drivers.Sqlite();
|
|
||||||
|
|
||||||
return db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
return db.MUser.select({name: MUser.name, email: MUser.email}).where(MUser.email == 'alice@example.com').first().next(function(row) {
|
||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,17 +1,84 @@
|
|||||||
package db;
|
package db;
|
||||||
|
|
||||||
// import tink.sql.drivers.Sqlite;
|
import tink.sql.drivers.Sqlite;
|
||||||
//import tink.sql.Database;
|
import tink.sql.Database;
|
||||||
import tink.sql.Types;
|
import tink.sql.Types;
|
||||||
import model.MUser;
|
import model.MUser;
|
||||||
|
import model.services.DrivebyCool;
|
||||||
// import db.Models.User;
|
import tink.CoreApi;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Db = tink.sql.Database<Def>;
|
|
||||||
@:tables(MUser)
|
@:tables(MUser)
|
||||||
interface Def extends tink.sql.DatabaseDefinition {
|
@:tables(MProject)
|
||||||
|
// Post related Tables
|
||||||
|
@:tables(MPost)
|
||||||
|
@:tables(MTag)
|
||||||
|
@:tables(MTaggedPost)
|
||||||
|
interface DbDef_DrivebyCool extends tink.sql.DatabaseDefinition {
|
||||||
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
|
//@:procedure var func:Int->{x:Int, point:tink.s2d.Point};
|
||||||
//@:table('user') var UserAlias:User;
|
@:table('user') var UserTbl:MUser;
|
||||||
|
// @:table('project') var ProjectTbl:DrivebyCool.MProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Db extends tink.sql.Database<DbDef_DrivebyCool> {
|
||||||
|
public function new(__name:String,driver:tink.sql.Driver){
|
||||||
|
super(__name, driver);
|
||||||
|
}
|
||||||
|
private static var driver = new tink.sql.drivers.Sqlite();
|
||||||
|
@async private static var db:Db = new Db('db.sqlite', driver);
|
||||||
|
@async public static function getDb()
|
||||||
|
{
|
||||||
|
return @await db;
|
||||||
|
}
|
||||||
|
public static function createTables():Void
|
||||||
|
{
|
||||||
|
var db = Db.getDb();
|
||||||
|
@async var execute = function(){
|
||||||
|
return db.MUser.create(true).next(function(_){
|
||||||
|
trace("aids");
|
||||||
|
return db.MProject.create(true);
|
||||||
|
}).next(function(_){
|
||||||
|
trace("aids");
|
||||||
|
return db.MPost.create(true);
|
||||||
|
}).next(function(_){
|
||||||
|
trace("aids");
|
||||||
|
return db.MTag.create(true);
|
||||||
|
}).next(function(_){
|
||||||
|
trace("aids");
|
||||||
|
return db.MTaggedPost.create(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@await execute().next(function(_){
|
||||||
|
trace(_);
|
||||||
|
return _;
|
||||||
|
}).handle(function(_){
|
||||||
|
trace(_);
|
||||||
|
});
|
||||||
|
// trace(two());
|
||||||
|
// @async var yeet = db.next(function(_db){
|
||||||
|
// return db.MUser.create();
|
||||||
|
// });
|
||||||
|
// yeet.next(function(_){
|
||||||
|
// trace("kanker");
|
||||||
|
// var test = @await db;
|
||||||
|
// return test.MProject.create(true);
|
||||||
|
// });
|
||||||
|
// .next(function(_){
|
||||||
|
// trace("kanker");
|
||||||
|
// return db.MPost.create(true);
|
||||||
|
// }).next(function(_){
|
||||||
|
// return db.MTag.create(true);
|
||||||
|
// }).next(function(_){
|
||||||
|
// return db.MTaggedPost.create(true);
|
||||||
|
// }).next(function(_){
|
||||||
|
// trace(_);
|
||||||
|
// });
|
||||||
|
// @await db.MProject.create(true);
|
||||||
|
// @await db.MPost.create(true);
|
||||||
|
// @await db.MTag.create(true);
|
||||||
|
// @await db.MTaggedPost.create(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,6 @@ import model.MService;
|
|||||||
typedef MUser = {
|
typedef MUser = {
|
||||||
@:autoIncrement @:primary public var id(default, null):Id<MUser>;
|
@:autoIncrement @:primary public var id(default, null):Id<MUser>;
|
||||||
public var name:VarChar<50>;
|
public var name:VarChar<50>;
|
||||||
public var email:VarChar<50>;
|
public var email:VarChar<256>;
|
||||||
public var password:VarChar<50>;
|
public var password:VarChar<256>;
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,55 @@
|
|||||||
package model.sites.drivebycool;
|
package model.services;
|
||||||
|
|
||||||
import tink.sql.Types;
|
import tink.sql.Types;
|
||||||
import model.MSubscription;
|
import model.MSubscription;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Project related models
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//Defines a Project to be listed on the projects page
|
||||||
typedef MProject = {
|
typedef MProject = {
|
||||||
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
|
@:autoIncrement @:primary public var id(default, null):Id<MProject>;
|
||||||
public var name:VarChar<50>;
|
// Properties
|
||||||
public var owner:Id<MUser>;
|
public var name:VarChar<50>;
|
||||||
public var description:VarChar<1024>;
|
public var owner:Id<MUser>;
|
||||||
|
public var description:VarChar<1024>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Defines a relationship between a Project and a User. The User will be added as a member of the project and can author blogposts
|
||||||
typedef MMembership = {
|
typedef MMembership = {
|
||||||
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
@:autoIncrement @:primary public var id(default, null):Id<MMembership>;
|
||||||
public var project:Id<MProject>;
|
// relationships
|
||||||
public var user:Id<MUser>;
|
public var project:Id<MProject>;
|
||||||
|
public var user:Id<MUser>;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Defines a Post
|
||||||
|
typedef MPost = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MPost>;
|
||||||
|
// Relationships
|
||||||
|
public var project:Id<MProject>;
|
||||||
|
public var owner:Id<MUser>;
|
||||||
|
// Properties
|
||||||
|
public var title:VarChar<1024>;
|
||||||
|
public var description:Text;
|
||||||
|
public var content:Text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defines a tag that can be added to any post.
|
||||||
|
typedef MTag = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MTag>;
|
||||||
|
public var title:VarChar<32>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defines a relationship between a tag and a post.
|
||||||
|
typedef MTaggedPost = {
|
||||||
|
@:autoIncrement @:primary public var id(default, null):Id<MTaggedPost>;
|
||||||
|
public var post:Id<MPost>;
|
||||||
|
public var tag:Id<MTag>;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user