@rameardo/cfw-framework v1.0.14
Welcome to the Superflow framework. Superflow Framework is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Superflow framework takes the pain out of development by easing common tasks used in many web projects, such as:
- Simple, fast routing engine
- Advanced request management
- Real-time event broadcasting with Websocket
- Expressive, intuitive database ORM
- Robust background job processing (Queue)
- Database agnostic schema migrations
This framework was built by admorris so that all developers can build cloudflare services/workers with fast performance and an easy look. The Superflow framework is simple to use and easy, and any developer can learn it easily.
Superflow Framework is currently not open source, which means you are not allowed to clone this repository.
Installation
npm i @super-flow/cfw-framework
In your entry js point (index.js
), replace your code with this
import { Superflow } from "@super-flow/cfw-framework";
const superflow = new Superflow();
// Routes path
import { routes } from "./routes";
/**
* Response HTTP request
* @event {DOM} fetch
*/
export default {
/**
* Initialize Superflow Framework
*
* @param {Request} request
* @param {Interface} env
* @returns <Superflow instance>
*/
async fetch(request, env) {
return await superflow.init(request, env, routes);
},
};
Routing
Create router file to define routes, in root directory create file with name routes.js
& paste following code
import { Home } from "./Controller/Home";
export const routes = [
{
route: "/",
method: "get",
controller: (params) => Home(params),
},
];
Controller
In root directory create new Folder with name Controllers
and inside this folder create new file with name Home.js
and paste following code
export const Home = (params) => {
const self = {
render: async () => {
return "Hello Superflow";
},
};
return self;
};
Now run your project with wrangler
wrangler dev
output should be Hello Superflow
Database Configuration
First of all, you have to configure your wrangler configuration for database binding (D1), add following block of code to your wrangler configuration file wrangler.toml
# Bind Database to project
d1_databases = [
{binding = "DB", database_name="[YOUR_DB_NAME]", database_id="[YOUR_DB_ID]", preview_database_id="[YOUR_DB_ID]"}
]
You can get your Database name & id from your > cloudflare dashboard.
Where is DB Instance?
in your controller, for example Controller/Home.js
, you recive from superflow framework
a paramter with name params
, this param contain
- Request information (
params.request
) - Database instance (
params.DB
)
You can in your self
object or for example render()
methood, define your Database constant to can use DB.
Controller Example
export const Test = (params) => {
const self = {
render: async () => {
const db = params.DB;
},
};
return self;
};
Variable db
is now an instance from Superflow Framework Database.
Database examples
Get all records
render: async () => {
// DB instance
const db = params.DB;
// Get all users
const users = await db.table("users").all();
// Return users as Object
return JSON.stringify(users);
};
Output
{
"table": "users",
"records": [
{
"id": 1,
"name": "Adnan Ali",
"email": "adnan@admorris.com",
},
{
"id": 2,
"name": "Support Team",
"email": "support@admorris.com",
}
],
"meta": {
"duration": 89.14580599963665,
"last_row_id": null,
"changes": null,
"served_by": "primary-ebec9042-0187-40df-a1f0-8aafa41db31f.db3",
"internal_stats": null
},
"total": 2,
"success": true,
"error": null,
"database_driver": "SuperFlow-CF-D1",
"date": "2022-11-19 19:06:28"
}
Get Single record under statment
render: async () => {
// DB instance
const db = params.DB;
// Get all users
const users = await db.table("users").where("id = 1").first();
// Return users as Object
return JSON.stringify(users);
};
Output
{
"table": "users",
"records": [
{
"id": 1,
"name": "Adnan A."
"email": "adnan@admorris.com",
}
],
"meta": {
"duration": 89.14580599963665,
"last_row_id": null,
"changes": null,
"served_by": "primary-ebec9042-0187-40df-a1f0-8aafa41db31f.db3",
"internal_stats": null
},
"total": 2,
"success": true,
"error": null,
"database_driver": "SuperFlow-CF-D1",
"date": "2022-11-19 19:06:28"
}
Security Vulnerabilities
If you discover a security vulnerability within Superflow Framework, please send an e-mail to Adnan Ali via adnan@admorris.com - or send to the Team developers@admorris.com . All security vulnerabilities will be promptly addressed.
License
This framework is under commerical license. You are not allowed to use this framework if you are not an employee of admorris (admorris.com).
Creadit
SuperFlow Cloudflare Worker Framework ~ Built with passion & ❤️ in admorris.