cerebras_coderqueries.ts5 matches
2import { ITERATIONS_TABLE, KEY, PROJECTS_TABLE, SCHEMA_VERSION } from "./migrations.ts";
34export async function createProject(prompt: string) {
5const projectResult = await sqlite.execute(
6`INSERT INTO ${PROJECTS_TABLE} (initial_prompt) VALUES (?)`,
11}
1213export async function getNextVersionNumber(projectId: number) {
14const data = await sqlite.execute(
15`SELECT version_number FROM ${ITERATIONS_TABLE}
21}
2223export async function insertVersion(projectId: number, versionNumber: number, prompt: string, code: string) {
24await sqlite.execute(
25`INSERT INTO ${ITERATIONS_TABLE}
29}
3031export async function getCodeInner(table: string, project: string, version?: string) {
32let data;
33if (version === undefined) {
50}
5152export async function getCode(project: string, version?: string) {
53// try to get code in the new table partition first
54const code = await getCodeInner(ITERATIONS_TABLE, project, version);
cerebras_codermigrations.ts1 match
7export const ITERATIONS_TABLE = "cerebras_coder_iterations";
89export async function createTables() {
10await sqlite.execute(`
11CREATE TABLE IF NOT EXISTS ${PROJECTS_TABLE} (
cerebras_codermain.tsx1 match
6await createTables();
78export default async function cerebras_coder(req: Request): Promise<Response> {
9if (req.method === "POST") {
10let { prompt, currentCode, versionHistory, projectId } = await req.json();
cerebras_coderindex.ts7 matches
23);
2425function Hero({
26prompt,
27setPrompt,
4445<p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
46Turn your ideas into fully functional apps in{" "}
47<span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
48less than a second
115}
116117function App() {
118const previewRef = React.useRef<HTMLDivElement>(null);
119const [prompt, setPrompt] = useState("");
169});
170171function handleStarterPromptClick(promptItem: typeof prompts[number]) {
172setLoading(true);
173setTimeout(() => handleSubmit(promptItem.prompt), 0);
174}
175176async function handleSubmit(e: React.FormEvent | string) {
177if (typeof e !== "string") {
178e.preventDefault();
225}
226227function handleVersionChange(direction: "back" | "forward") {
228const { currentVersionIndex, versions } = versionHistory;
229if (direction === "back" && currentVersionIndex > 0) {
973);
974975function client() {
976const path = window.location.pathname;
977const root = createRoot(document.getElementById("root")!);
cerebras_coderindex.html1 match
19<meta property="og:site_name" content="Cerebras Coder">
20<meta property="og:url" content="https://cerebrascoder.com"/>
21<meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
22<meta property="og:type" content="website">
23<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
cerebras_codergenerate-code.ts2 matches
2import STARTER_PROMPTS from "../public/starter-prompts.js";
34function extractCodeFromFence(text: string): string {
5const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
6return htmlMatch ? htmlMatch[1].trim() : text;
7}
89export async function generateCode(prompt: string, currentCode: string) {
10const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
11if (starterPrompt) {
Websitequeries.ts4 matches
3import type { Product, Transaction } from "../../shared/types.ts";
45export async function getAllProducts(): Promise<Product[]> {
6const result = await sqlite.execute(`SELECT * FROM ${PRODUCTS_TABLE} ORDER BY id`);
7return result.rows?.map(row => ({
14}
1516export async function getProductById(id: number): Promise<Product | null> {
17const result = await sqlite.execute(`SELECT * FROM ${PRODUCTS_TABLE} WHERE id = ?`, [id]);
18if (result.rows && result.rows.length > 0) {
29}
3031export async function createTransaction(productId: number, productName: string, price: number): Promise<Transaction> {
32const timestamp = new Date().toISOString();
33
58}
5960export async function getAllTransactions(): Promise<Transaction[]> {
61const result = await sqlite.execute(`SELECT * FROM ${TRANSACTIONS_TABLE} ORDER BY timestamp DESC`);
62return result as Transaction[];
Websitemigrations.ts2 matches
4const TRANSACTIONS_TABLE = 'ecommerce_transactions_1';
56export async function runMigrations() {
7// Create products table
8await sqlite.execute(`CREATE TABLE IF NOT EXISTS ${PRODUCTS_TABLE} (
31}
3233async function insertSampleProducts() {
34const sampleProducts = [
35{
untitled-3477dailyFactTweet.ts5 matches
49* Generate OAuth 1.0a signature for Twitter API
50*/
51async function generateTwitterSignature(
52method: string,
53url: string,
102* Post a tweet to Twitter using the v1.1 API
103*/
104async function postTweet(text: string, credentials: TwitterCredentials): Promise<boolean> {
105const url = 'https://api.twitter.com/1.1/statuses/update.json';
106const method = 'POST';
147* Get a random fact from our collection
148*/
149function getRandomFact(): RandomFact {
150const randomIndex = Math.floor(Math.random() * RANDOM_FACTS.length);
151return RANDOM_FACTS[randomIndex];
153154/**
155* Main function - posts a random fact to Twitter
156*/
157export default async function(): Promise<void> {
158console.log('🤖 Daily Fact Bot starting...');
159
cqueries.ts15 matches
34// User queries
5export async function getUserByEmail(email: string): Promise<User | null> {
6const result = await sqlite.execute("SELECT * FROM users WHERE email = ?", [email]);
7return result.rows[0] as User || null;
8}
910export async function createUser(userData: Omit<User, 'id' | 'created_at'>): Promise<number> {
11const result = await sqlite.execute(`
12INSERT INTO users (email, password, name, phone, role)
1718// Customer queries
19export async function getAllCustomers(): Promise<Customer[]> {
20const result = await sqlite.execute("SELECT * FROM customers ORDER BY name");
21return result as Customer[];
22}
2324export async function getCustomerById(id: number): Promise<Customer | null> {
25const result = await sqlite.execute("SELECT * FROM customers WHERE id = ?", [id]);
26return result[0] as Customer || null;
27}
2829export async function createCustomer(customerData: Omit<Customer, 'id' | 'created_at'>): Promise<number> {
30const result = await sqlite.execute(`
31INSERT INTO customers (name, email, phone, address)
35}
3637export async function updateCustomer(id: number, customerData: Partial<Customer>): Promise<void> {
38const fields = [];
39const values = [];
6364// Bill queries
65export async function getAllBills(): Promise<Bill[]> {
66const result = await sqlite.execute(`
67SELECT b.*, c.name as customer_name, c.phone as customer_phone, c.email as customer_email
77}
7879export async function getBillsByCustomerId(customerId: number): Promise<Bill[]> {
80const result = await sqlite.execute(`
81SELECT b.*, c.name as customer_name, c.phone as customer_phone, c.email as customer_email
92}
9394export async function getBillById(id: number): Promise<Bill | null> {
95const result = await sqlite.execute(`
96SELECT b.*, c.name as customer_name, c.phone as customer_phone, c.email as customer_email
109}
110111export async function createBill(billData: {
112customer_id: number;
113bill_number: string;
142}
143144export async function updateBill(id: number, billData: Partial<Bill>): Promise<void> {
145const fields = [];
146const values = [];
194}
195196export async function deleteBill(id: number): Promise<void> {
197await sqlite.execute("DELETE FROM payments WHERE bill_id = ?", [id]);
198await sqlite.execute("DELETE FROM bills WHERE id = ?", [id]);
200201// Payment queries
202export async function getPaymentsByBillId(billId: number): Promise<Payment[]> {
203const result = await sqlite.execute(
204"SELECT * FROM payments WHERE bill_id = ? ORDER BY payment_date DESC",
208}
209210export async function createPayment(paymentData: {
211bill_id: number;
212amount: number;
228}
229230export async function generateBillNumber(): Promise<string> {
231const result = await sqlite.execute("SELECT COUNT(*) as count FROM bills");
232const count = result[0].count as number;