1. Install the Quill SDK
npm install @quillsql/node
pip3 install quillsql
go get https://github.com/quill-sql/quill-go
composer require quill.co/quill-php
bundle install quill-sql
2. Create a new endpoint
InstantiateQuill with your credentials and add the below POST endpoint.
import { Quill } from "@quillsql/node";
const quill = new Quill({
privateKey: process.env.QULL_PRIVATE_KEY,
databaseConnectionString: process.env.POSTGRES_READ,
databaseType: "postgresql",
});
// "authenticateJWT" is your own pre-existing auth middleware
app.post("/quill", authenticateJWT, async (req, res) => {
// assuming user fetched via auth middleware has an userId
const { userId } = req.user;
const { metadata } = req.body;
const result = await quill.query({
tenants: [{ tenantField: "user_id", tenantIds: [userId] }]
metadata,
});
res.send(result);
});
from quillsql import Quill
quill = Quill(
private_key=os.getenv("QULL_PRIVATE_KEY"),
database_connection_string=os.getenv("POSTGRES_READ"),
database_type="postgresql"
)
security = HTTPBearer()
async def authenticate_jwt(token: str = Depends(security)):
# Your JWT validation logic here
# Return user object or raise HTTPException
user = validate_jwt_token(token.credentials)
return user
@app.post("/quill")
async def quill_post(data: Request, user: dict = Depends(authenticate_jwt)):
# assuming user fetched via auth middleware has an userId
user_id = user["user_id"]
body = await data.json()
metadata = body.get("metadata")
result = await quill.query(
tenants=[{"tenantField": "user_id", "tenantIds": [user_id]}],
metadata=metadata
)
return result
import (
"github.com/quill-sql/quill-go"
)
client := quill.NewClient(quill.ClientParams{
PrivateKey: os.Getenv("QUILL_PRIVATE_KEY"),
DatabaseConnectionString: os.Getenv("POSTGRES_READ")
})
// Add an endpoint
http.HandleFunc("/quill", func(w http.ResponseWriter, r *http.Request) {
// fetch organizationID from your existing auth middleware
organizationID, _ := r.Context().Value(OrganizationIDContextKey).(string)
// Convert json body.metadata to RequestMetadata
body := &quill.RequestBody{}
err := json.NewDecoder(r.Body).Decode(body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
result, err := client.Query(organizationID, body.Metadata)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(result)
})
<?php
require __DIR__ . "/vendor/autoload.php";
$quill = new \Quill\Quill($privateKey, $databaseType, $databaseConnectionString);
if ($requestMethod === 'POST' && $endpoint === '/quill') {
// authUser is an example of how you might reference your existing authenticated user.
// 'company_id' is an example of what your organizationId field might be
$orgId = $authUser['company_id'];
$input = file_get_contents('php://input');
$data = json_decode($input, true);
$params = [
'metadata' => $data['metadata'],
'orgId' => $orgId
];
$response = $quill->query($params);
header('Content-Type: application/json');
$body = json_encode($response, JSON_PRETTY_PRINT);
echo $body;
exit;
}
require "quill-sql"
quill = Quill.new(
private_key: ENV["PRIVATE_KEY"],
database_connection_string: ENV["DB_URL"],
database_type: "clickhouse"
)
post "/quill" do
# Assuming user fetched via auth middleware has a user_id
org_id = request.env["org_id"]
metadata = JSON.parse(request.body.read)["metadata"]
result = quill.query(
tenants: [{ tenantField: "org_id", tenantIds: [org_id] }],
metadata: metadata
)
result.to_json
end
3. Connect the frontend
You connect Quill to React with theQuillProvider component. Similar to React’s Context.Provider, QuillProvider wraps your React app and places Quill Client on the context, enabling you to access it from anywhere in your component tree.
In App.js, let’s wrap our React app with an QuillProvider. We suggest putting the QuillProvider somewhere high in your app, above any component that might need to access Quill data.
App.js
import { QuillProvider } from "@quillsql/react";
import Routes from "./Routes";
import UserContext from "./UserContext";
function App() {
// Use your existing auth and user context
const [user] = useContext(UserContext);
return (
<QuillProvider
publicKey="YOUR_PUBLIC_KEY"
queryEndpoint="https://yourserver.com/quill" // your POST endpoint
queryHeaders={{
// We'll pass these headers on every request to your endpoint
Authorization: `Bearer ${user.jwt}`,
}}
>
<Routes />
</QuillProvider>
);
}
See the
QuillProvider API docs for more
information.
