Moquilang WebAssembly Module
This is a WebAssembly module built with Rust that provides entity operations and service calls for JavaScript applications. It includes a complete user management service and SQLite database integration.
Features
- User Management: Complete CRUD operations for user entities
- Entity Operations: Generic entity creation, retrieval, update, and deletion
- Service Framework: Extensible service call infrastructure
- SQLite Integration: Browser-based SQLite database support
- WebAssembly Performance: Native-like performance in the browser
Directory structure
pkg/- Contains WebAssembly build artifacts and generated JavaScript bindingsstatic/- Contains SQLite library and other JavaScript dependenciesindex.html- Example HTML file demonstrating usage of the WebAssembly module
Usage
To use the WebAssembly module in your HTML file:
<!-- Include the SQLite library -->
<!-- Import the WebAssembly module -->
Available Functions
callService(name: string, parameters: object) -> Promise
Calls a service with the given name and parameters. The parameters can be any JSON-serializable object. This function uses the JSON-based approach for serialization/deserialization between JavaScript and Rust, which can be more efficient in many cases.
import from "./pkg/moquilang.js";
// Example usage
const result = await ;
// The result will contain:
// {
// service: "userService",
// status: "success",
// parameters: "{userId: 123, action: \"getProfile\", options: {...}}"
// }
Note: This implementation uses the JSON-based approach with gloo-utils rather than direct JavaScript value manipulation with serde-wasm-bindgen. This approach:
- Is often faster for simple data structures
- Has better compatibility with browser JSON implementations
- Supports all JSON-serializable types
- May have a slightly larger code size
Entity Operations
The module provides the following entity operation functions:
createEntity(entityName: string, entityData: object) -> Promise
Creates a new entity with the given name and data.
import from "./pkg/moquilang.js";
// Example usage
const result = await ;
updateEntity(entityName: string, entityData: object) -> Promise
Updates an existing entity. The entity ID must be included in the entityData.
import from "./pkg/moquilang.js";
// Example usage
const result = await ;
deleteEntity(entityName: string, entityData: object) -> Promise
Deletes an entity. The entity ID must be included in the entityData.
import from "./pkg/moquilang.js";
// Example usage
const result = await ;
findOne(entityName: string, query: object) -> Promise
Finds one entity matching the query.
import from "./pkg/moquilang.js";
// Example usage
const result = await ;
findMany(entityName: string, query: object) -> Promise<object[]>
Finds multiple entities matching the query.
import from "./pkg/moquilang.js";
// Example usage
const results = await ;
Building the Project
- Build the WebAssembly module from source:
# Build the Rust WebAssembly module
The project includes a build.rs script that automatically runs wasm-bindgen after successful compilation when targeting wasm32-unknown-unknown. The generated files will be placed in the pkg/ directory.
For a release build:
- Start a local development server with:
- Go to http://localhost:8000 in your browser
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.