{"id":43903267,"url":"https://github.com/singlestore-labs/singlestore-cloudflare-external-functions","last_synced_at":"2026-02-06T19:20:38.654Z","repository":{"id":104432604,"uuid":"428794858","full_name":"singlestore-labs/singlestore-cloudflare-external-functions","owner":"singlestore-labs","description":"Example of how to use SingleStore External Functions with CloudFlare Workers","archived":false,"fork":false,"pushed_at":"2024-03-08T16:20:50.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-18T02:14:35.545Z","etag":null,"topics":["cloudflare","cloudflare-workers","singlestore","sql","udf"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/singlestore-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-16T19:55:52.000Z","updated_at":"2022-02-26T17:19:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"4fe8c914-074a-4e6a-998e-174f0f7e5f06","html_url":"https://github.com/singlestore-labs/singlestore-cloudflare-external-functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/singlestore-labs/singlestore-cloudflare-external-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singlestore-labs%2Fsinglestore-cloudflare-external-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singlestore-labs%2Fsinglestore-cloudflare-external-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singlestore-labs%2Fsinglestore-cloudflare-external-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singlestore-labs%2Fsinglestore-cloudflare-external-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/singlestore-labs","download_url":"https://codeload.github.com/singlestore-labs/singlestore-cloudflare-external-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/singlestore-labs%2Fsinglestore-cloudflare-external-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29173490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T16:33:35.550Z","status":"ssl_error","status_checked_at":"2026-02-06T16:33:30.716Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","cloudflare-workers","singlestore","sql","udf"],"created_at":"2026-02-06T19:20:38.073Z","updated_at":"2026-02-06T19:20:38.639Z","avatar_url":"https://github.com/singlestore-labs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SingleStore External Functions + Cloudflare Workers\n\n**Attention**: The code in this repository is intended for experimental use only and is not fully tested, documented, or supported by SingleStore. Visit the [SingleStore Forums](https://www.singlestore.com/forum/) to ask questions about this repository.\n\nThis is an example of using [CloudFlare Workers][cloudflare-workers] along with [SingleStore External Functions][docs-ef].\n\nSingleStore External Functions is a feature in SingleStore which allows the engine to send and receive rows to an external HTTP service during query execution. Using this feature, we can augment SingleStore's capabilities with new functionality.\n\n**Example use cases:**\n\n* Translating text content between languages using [Amazon Translate][aws-translate]\n* Performing sentiment analysis (included in this repository)\n* Loading data from an external API (included in this repository)\n* Pushing or pulling data to or from an external system\n* ...anything else you can put behind an HTTP server 😊\n\n## Setup\n\n1. [Sign up](https://www.singlestore.com/try-free/) for a free SingleStore license. This allows you to run up to 4 nodes up to 32 gigs each for free. Grab your license key from [SingleStore portal](https://portal.singlestore.com/?utm_medium=osm\u0026utm_source=github) and set it as an environment variable.\n\n   ```bash\n   export SINGLESTORE_LICENSE=\"singlestore license\"\n   ```\n\n2. Setup a SingleStore cluster. You can use the provided `start.sh` script to spin up a cluster using Docker on this machine. **Note: this does not work on M1 Mac machines**.\n\n## Publishing a CloudFlare Worker\n\nThis repo is already setup to publish a worker to CloudFlare using their wrangler tool. The following steps should work, however if you run into issues please refer to [CloudFlare's official documentation][cfw-docs].\n\n```bash\nyarn install\nyarn run wrangler login # only need to run this once per machine\nyarn run wrangler publish --name s2-ef-demo index.js\n```\n\nIf everything works, you should receive a url like `s2-ef-demo.SUBDOMAIN.workers.dev`. The SUBDOMAIN will be specific to your CloudFlare account.\n\n## Creating the external function\n\nTo enable external functions you must first connect to your SingleStore cluster and run:\n\n```sql\nset global enable_external_functions = ON;\n```\n\n\u003e ❗ **Note:** If you are using SingleStore managed service you will need to file a support ticket to enable this feature on your cluster, along with any specific domains you will be accessing (like `*.workers.dev`).\n\nOnce external functions are enabled, you can create a database and use them easily. Here is how you would use the sentiment function we deployed to CloudFlare workers:\n\n```sql\ncreate database if not exists demo;\nuse demo;\n\nCREATE OR REPLACE EXTERNAL FUNCTION sentiment (body TEXT)\nRETURNS DOUBLE\nAS REMOTE SERVICE \"s2-ef-demo.YOUR_WORKER_SUBDOMAIN.workers.dev/sentiment\"\nFORMAT JSON;\n\n-- change the string here to see the sentiment of different content\nselect sentiment(\"i love external functions\");\n\n-- lets run it on a table\ncreate table if not exists posts (id int, body text);\ninsert into posts values (1, \"external functions are super cool\");\ninsert into posts values (2, \"read the damn docs!\");\ninsert into posts values (3, \"I am a huge fan of pineapples\");\n\nselect body, sentiment(body) from posts;\n```\n\nAnd here is how you would use the coincap assets function we deployed:\n\n```sql\ncreate database if not exists demo;\nuse demo;\n\nCREATE OR REPLACE EXTERNAL FUNCTION coincap_assets (search TEXT)\nRETURNS TABLE(data TEXT)\nAS REMOTE SERVICE \"s2-ef-demo.YOUR_WORKER_SUBDOMAIN.workers.dev/coincap/assets\"\nFORMAT JSON;\n\nselect * from coincap_assets(\"BTC\");\n\nselect\n    data::$name,\n    format(data::%marketCapUsd, 0),\n    format(data::%changePercent24Hr, 2)\nfrom coincap_assets(\"BTC\")\norder by data::%changePercent24Hr desc;\n```\n\n## Exercises\n\nNow that you have a working endpoint, let's define some more! Modify index.js to add additional endpoints to the router and then re-publish the file to cloudflare workers. Then create a new function for each of your endpoints.\n\nIdeas:\n1. Create a function which transforms strings to uppercase\n2. Create a function which returns the number of words in a string\n3. Create a function which takes multiple arguments\n4. Create a function which queries an external API\n\n## Resources\n\n* [Documentation](https://docs.singlestore.com)\n* [Twitter](https://twitter.com/SingleStoreDevs)\n* [SingleStore Forums](https://www.singlestore.com/forum)\n\n\n[docs-ef]: https://docs.singlestore.com/db/latest/en/reference/sql-reference/procedural-sql-reference/create--or-replace--external-function.html\n[cloudflare-workers]: https://workers.cloudflare.com/\n[cfw-docs]: https://developers.cloudflare.com/workers/\n[aws-translate]: https://aws.amazon.com/translate/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinglestore-labs%2Fsinglestore-cloudflare-external-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinglestore-labs%2Fsinglestore-cloudflare-external-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinglestore-labs%2Fsinglestore-cloudflare-external-functions/lists"}