Thanks to visit codestin.com
Credit goes to deepwiki.com

Menu

Database and Game Examples

Relevant source files

This document demonstrates practical applications of OwnLang's module system through database connectivity and interactive game development examples. It showcases advanced integration patterns combining multiple modules to create sophisticated applications including JDBC database operations, real-time multiplayer games, and network API consumption.

For basic module usage patterns, see Module Architecture. For network-specific examples, see Network Programming Examples.

Database Connectivity

OwnLang provides database connectivity through the jdbc module, enabling standard SQL database operations with various database engines including HSQLDB and SQLite.

Database Connection Pattern

HSQLDB Database Operations

The HSQLDB example demonstrates file-based database operations with table creation, data insertion, and querying:

OperationMethod CallPurpose
ConnectiongetConnection("jdbc:hsqldb:file:hsql.db", "", "", "org.hsqldb.jdbcDriver")Establish database connection
Table CreationexecuteUpdate("CREATE TABLE cities (id IDENTITY, name VARCHAR(32))")Define schema
Data InsertionexecuteUpdate("INSERT INTO cities (name) VALUES('Киев')")Insert records
Data QueryingexecuteQuery("SELECT id, name FROM cities")Retrieve data
Shutdownexecute("SHUTDOWN")Close database properly

SQLite Database Operations

The SQLite example shows lightweight database operations with query timeout configuration:

OperationCode PatternNotes
ConnectiongetConnection("jdbc:sqlite:sample.db")File-based SQLite database
TimeoutsetQueryTimeout(30)30-second query timeout
Schemacreate table person (id integer, name string)Simple table structure
Data Accessrs.getString("name"), rs.getInt("id")Typed data retrieval

Sources: examples/database/hsqldb.own1-18 examples/database/sqlite.own1-20

Interactive Game Development

The pipes game example demonstrates complex application development combining graphics rendering, user input handling, and real-time networking.

Game Architecture Components

Game State Management

The pipes game implements a dual-board system with local and remote player states:

ComponentData StructurePurpose
board[SIZE][SIZE]2D arrayLocal player's game state
boardGhost[SIZE][SIZE]2D arrayRemote player's game state
Cells[]Object arrayCell type definitions and transitions
curX, curYIntegersLocal player cursor position
curGhostX, curGhostYIntegersRemote player cursor position

Real-time Communication Pattern

Socket Event Handlers

The game implements several socket event listeners for real-time synchronization:

Sources: examples/game/pipes_online.own1-174

Advanced Integration Patterns

Complex applications often require integration of multiple modules to achieve sophisticated functionality.

Multi-Module Integration Example

The GitHub timeline example demonstrates module composition for API consumption:

ModuleFunctions UsedPurpose
httphttp(), thread()HTTP requests and threading
jsonjsondecode()JSON response parsing
functionalforeach()Data iteration
dateformatDate(), parseDate()Date formatting
stdprintln, match, length()Standard operations

Threaded HTTP Processing

The example shows both synchronous and asynchronous HTTP patterns:

Pattern Matching for Event Types

The application uses pattern matching to handle different GitHub event types, demonstrating complex control flow:

Sources: examples/network/github_timeline.own1-44

Summary

These examples demonstrate OwnLang's capabilities for:

  • Database Integration: JDBC-based connectivity with multiple database engines
  • Real-time Applications: Socket.io integration for multiplayer games
  • Graphics Programming: Canvas-based rendering and user interface development
  • API Consumption: HTTP client usage with JSON processing
  • Complex Data Flow: Module composition and pattern matching

The examples showcase how OwnLang's module system enables rapid development of sophisticated applications through clean integration patterns and expressive language constructs.

Sources: examples/database/hsqldb.own examples/database/sqlite.own examples/game/pipes_online.own examples/network/github_timeline.own