gopherbase
v1.0.6
Published
The official JavaScript/TypeScript client for GopherBase.
Maintainers
Readme
GopherBase
GopherBase is a PostgreSQL-based database management system with a Go backend and React frontend. It provides a Supabase-like experience for managing your data, schema, and storage with built-in AI capabilities.
Prerequisites
- Docker
- Docker Compose
Quick Start
docker-compose up -dAccess the dashboard at http://localhost:4173
Docker Compose Configuration
To run GopherBase locally, you can use the following docker-compose.yml configuration:
version: '3.8'
services:
backend:
image: ethicalgopher/gopherbase:latest
ports:
- "8080:8080"
environment:
- DATABASE_URL=postgres://gopherbase:gopherbase@postgres:5432/gopherbase?sslmode=disable
- JWT_SECRET=${JWT_SECRET:-dev-secret}
- OLLAMA_HOST=http://ollama:11434
restart: unless-stopped
depends_on:
- postgres
- ollama
networks:
- gopherbase-network
frontend:
image: ethicalgopher/gopherbase-frontend:latest
ports:
- "4173:4173"
restart: unless-stopped
depends_on:
- backend
networks:
- gopherbase-network
postgres:
image: postgres:16-alpine
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_USER: gopherbase
POSTGRES_PASSWORD: gopherbase
POSTGRES_DB: gopherbase
restart: unless-stopped
networks:
- gopherbase-network
ollama:
image: ollama/ollama:latest
volumes:
- ollama_data:/root/.ollama
restart: unless-stopped
entrypoint: >
/bin/bash -c "
ollama serve &
until ollama list > /dev/null 2>&1; do sleep 2; done &&
ollama pull mistral:7b-instruct &&
wait
"
networks:
- gopherbase-network
volumes:
postgres_data:
ollama_data:
networks:
gopherbase-network:
driver: bridgeServices Overview
| Service | Image | Port | Description |
|---------|-------|------|-------------|
| backend | ethicalgopher/gopherbase:latest | 8080 | Go Fiber API server |
| frontend | ethicalgopher/gopherbase-frontend:latest | 4173 | Vite React application |
| postgres | postgres:16-alpine | 5432 | PostgreSQL database |
| ollama | ollama/ollama:latest | 11434 | Local LLM service (mistral:7b-instruct) |
Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| DATABASE_URL | postgres://gopherbase:gopherbase@postgres:5432/gopherbase?sslmode=disable | PostgreSQL connection string |
| JWT_SECRET | dev-secret | JWT authentication secret |
| OLLAMA_HOST | http://ollama:11434 | Ollama service URL |
Ports Mapping
| Service | Internal | External | |---------|----------|----------| | Backend API | 8080 | 8080 | | Frontend | 4173 | 4173 | | PostgreSQL | 5432 | - | | Ollama | 11434 | - |
Common Tasks
# Start services
docker-compose up -d
# Stop services
docker-compose down
# View logs
docker-compose logs -f
# Rebuild images
docker-compose build --no-cacheJavaScript/TypeScript SDK
Installation
npm install gopherbaseQuick Start
import { createClient } from 'gopherbase';
const client = createClient('http://localhost:8080', 'your-public-key');
// Fetch data
const users = await client
.from("users")
.select("id, name, email")
.where("age.gt.18")
.execute();
// Insert data
await client
.from("users")
.insert({
name: "John",
email: "[email protected]",
age: 25
})
.execute();Authentication (React)
import { AuthProvider, useAuth } from 'gopherbase';
function App() {
return (
<AuthProvider url="http://localhost:8080">
<MyComponent />
</AuthProvider>
);
}
function MyComponent() {
const { user, signIn, signOut } = useAuth();
const handleSignIn = () => signIn('[email protected]', 'password');
return user ? (
<button onClick={signOut}>Sign Out</button>
) : (
<button onClick={handleSignIn}>Sign In</button>
);
}Raw SQL Execution
const result = await client.execute("SELECT * FROM users WHERE age > 18");API Reference
createClient(url, key)
Creates a new GopherBase client instance.
url: The GopherBase server URL.key: Your API key.
client.schema.create(table)
Starts a schema creation chain.
.column(name, type): Define a column..primary(): Set as primary key..autoIncrement(): Enable auto-increment..notNull()/.nullable(): Set nullability..unique(): Set UNIQUE constraint..default(value): Set default value..references(table, column): Add foreign key reference..execute(): Execute the schema creation.
client.from(table)
Returns a QueryBuilder for the specified table.
.select(columns): Select specific columns (default: *)..where(condition): Add string-based where clauses (e.g.,age.gt.18)..match(object): Filter by exact key-value pairs..insert(data): Insert a record..update(data): Update records matching.match()..delete(): Delete records matching.match()..execute(): Execute the query.
client.ai.query(prompt, mode?)
Perform an AI-powered query using natural language.
client.storage.from(bucket)
Manage files in a specific bucket.
.listFiles().upload(file).delete(filename).getPublicUrl(filename)
Supported Column Types
- INT, BIGINT
- VARCHAR, TEXT
- BOOLEAN
- TIMESTAMP, DATE, TIME
- FLOAT, DOUBLE
License
MIT
