Skip to content

A high performance sqlite database built ontop of bun.js

License

Notifications You must be signed in to change notification settings

MalikWhitten67/xavierdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xavierdb

A high performance sqlite database built ontop of bun.js

Installation

  1. Install Bun.js if not already installed
  2. Download a release for your system whether linux macos or windows.

Use as standalone app

You could download the prebuilt executable for your platform from the Releases Tab. Once downloaded, extract the archive

Create a schema.cbf file and a .env file

.cbf format is utilized simarly to a sql file - cbf files define collections and relations between them! cleaner than utilizing config.ts files.

# ensure that for every colon there is a comma else it will throw an error!
# @auth specifies that the collection is authenticated and will allow you to utilize password auth
collection users { 
        name: string & required,
        email: string & required,
        password: string & required,
        role: string,
        @auth: true,
} 
end;

collection posts {
   title: string,
   content: string,
   user_id: number,  
}
end;

@relation {
    posts: user_id -> users using id,  // posts: utilizes user_id as the users id <simiplified> - when queried it will return the user
    // of that post
} 
end;
 
 

Now that you have configured your collection schemes it will generate types based off of that Next is creating a .env file to hide some stuff

HTTP_REQUEST_PORT=8080 # The port the server will run on
DATA_DIR=/data # directory where the data is stored
LOG_DIR=/logs # directory where the logs are stored
CPU_LIMIT=1000 # The maximum CPU usage in milliseconds
MEMORY_LIMIT=512 # The maximum memory usage in MB
COMPRESSION_LEVEL=1 # The compression level for the server
LOG_LEVEL=ERROR # The log level for the server
SECRET_KEY=secret # The secret key for the server
TOKEN_EXPIRY=1h # The expiry time for the token 
HTTP_MAX_REQUEST_SIZE=1000000  # The maximum request size in bytes
HTTP_MAX_REQUEST_TIMEOUT=10000  # The maximum request timeout in milliseconds
RATELIMITS_ENABLED=false # Enable or disable ratelimits 
RATELIMITS_WINDOW=1m # The window for the ratelimits
RATELIMITS_MAX_REQUESTS=100 # The maximum requests for the ratelimits

almost done all you have to do is define routes - create a routes folder if not done already - this folder allows you to use a filebased routing approach similar to nextjs to define api routes, this is where all custom validation goes.

if you have ratelimits enabled you need to first send the user to grab a token at /api/session then append that token to Authorization-Session this will allow the server to keep track of the user's request times and uses

// routes/index.ts 
import xavier from 'xaviderdb/client' //  this is an autogenerated file with types for each collection 
export default function GET(req: typeof RequestData) {     
  return new Response(
    JSON.stringify(
      xavier.users.getAll()
    ),
    { status: 200, headers: { "Content-Type": "application/json" } }
  );
}

Lastly run ./xavier --serve

Build yourself

You can use custom code and build your own executable by following the steps below // platform = windows | linux Simply clone the project then extract and run ./build.sh file

About

A high performance sqlite database built ontop of bun.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published